mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 07:26:09 +00:00 
			
		
		
		
	Test pdf liste
This commit is contained in:
		
							parent
							
								
									e172fd458e
								
							
						
					
					
						commit
						08bbf8cd07
					
				
					 2 changed files with 54 additions and 33 deletions
				
			
		|  | @ -31,10 +31,9 @@ namespace AideDeJeu.Pdf | ||||||
| 
 | 
 | ||||||
|         Document _Document = null; |         Document _Document = null; | ||||||
|         PdfWriter _Writer = null; |         PdfWriter _Writer = null; | ||||||
|         public void MarkdownToPdf(string md, Stream stream) |         public void MarkdownToPdf(List<string> mds, Stream stream) | ||||||
|         { |         { | ||||||
|             var pipeline = new Markdig.MarkdownPipelineBuilder().UseYamlFrontMatter().UsePipeTables().Build(); |             var pipeline = new Markdig.MarkdownPipelineBuilder().UseYamlFrontMatter().UsePipeTables().Build(); | ||||||
|             var parsed = Markdig.Markdown.Parse(md, pipeline); |  | ||||||
| 
 | 
 | ||||||
|             _Document = new Document(new Rectangle(822, 1122)); |             _Document = new Document(new Rectangle(822, 1122)); | ||||||
|             _Writer = PdfWriter.GetInstance(_Document, stream); |             _Writer = PdfWriter.GetInstance(_Document, stream); | ||||||
|  | @ -44,35 +43,56 @@ namespace AideDeJeu.Pdf | ||||||
|             //PdfStamper stamper = null; |             //PdfStamper stamper = null; | ||||||
|             //stamper = new PdfStamper(reader, stream); |             //stamper = new PdfStamper(reader, stream); | ||||||
| 
 | 
 | ||||||
|             Render(parsed.AsEnumerable()); |             foreach (var md in mds) | ||||||
|  |             { | ||||||
|  |                 var parsed = Markdig.Markdown.Parse(md, pipeline); | ||||||
|  |                 Render(parsed.AsEnumerable(), _Document); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             _Document.Close(); |             _Document.Close(); | ||||||
|             _Writer.Close(); |             _Writer.Close(); | ||||||
|             //stamper.Close(); |             //stamper.Close(); | ||||||
|             //reader.Close(); |             //reader.Close(); | ||||||
|         } |         } | ||||||
|         private void Render(IEnumerable<Block> blocks) |         private void Render(IEnumerable<Block> blocks, Document document) | ||||||
|         { |         { | ||||||
|  |             var phrases = Render(blocks); | ||||||
|  |             foreach(var phrase in phrases) | ||||||
|  |             { | ||||||
|  |                 document.Add(phrase); | ||||||
|  |                 //ColumnText ct = new ColumnText(_Writer.DirectContent); | ||||||
|  |                 //ct.AddText(CreateFormatted(block.Inline, Font.HELVETICA, 0, new Color(0, 0, 0), 12)); | ||||||
|  |                 //ct.Alignment = Element.ALIGN_JUSTIFIED; | ||||||
|  |                 //ct.SetSimpleColumn(10, 10, 200, 200); | ||||||
|  |                 //ct.Go(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         private IEnumerable<Phrase> Render(IEnumerable<Block> blocks) | ||||||
|  |         { | ||||||
|  |             var phrases = new List<Phrase>(); | ||||||
|             foreach (var block in blocks) |             foreach (var block in blocks) | ||||||
|             { |             { | ||||||
|                 this.Render(block); |                 var phrase = this.Render(block); | ||||||
|  |                 if(phrase != null) | ||||||
|  |                 { | ||||||
|  |                     phrases.Add(phrase); | ||||||
|  |                 } | ||||||
|                 if (block.IsBreakable) |                 if (block.IsBreakable) | ||||||
|                 { |                 { | ||||||
|                     _Document.Add(Chunk.NEWLINE); |                     phrases.Add(new Phrase(Chunk.NEWLINE)); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |             return phrases; | ||||||
|         } |         } | ||||||
|         private void Render(Block block) |         private Phrase Render(Block block) | ||||||
|         { |         { | ||||||
|             switch (block) |             switch (block) | ||||||
|             { |             { | ||||||
|                 case HeadingBlock heading: |                 case HeadingBlock heading: | ||||||
|                     Render(heading); |                     return Render(heading); | ||||||
|                     break; |  | ||||||
| 
 | 
 | ||||||
|                 case ParagraphBlock paragraph: |                 case ParagraphBlock paragraph: | ||||||
|                     Render(paragraph); |                     return Render(paragraph); | ||||||
|                     break; |  | ||||||
| 
 | 
 | ||||||
|                 //case QuoteBlock quote: |                 //case QuoteBlock quote: | ||||||
|                 //    Render(quote); |                 //    Render(quote); | ||||||
|  | @ -100,7 +120,7 @@ namespace AideDeJeu.Pdf | ||||||
| 
 | 
 | ||||||
|                 default: |                 default: | ||||||
|                     Debug.WriteLine($"Can't render {block.GetType()} blocks."); |                     Debug.WriteLine($"Can't render {block.GetType()} blocks."); | ||||||
|                     break; |                     return null; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             //if (queuedViews.Any()) |             //if (queuedViews.Any()) | ||||||
|  | @ -113,18 +133,14 @@ namespace AideDeJeu.Pdf | ||||||
|             //} |             //} | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void Render(HeadingBlock block) |         private Phrase Render(HeadingBlock block) | ||||||
|         { |         { | ||||||
|             _Document.Add(CreateFormatted(block.Inline, Font.HELVETICA, 0, new Color(0x9B1C47), 20 + (7 - block.Level) * 2)); |             return CreateFormatted(block.Inline, Font.HELVETICA, 0, new Color(0x9B1C47), 14 + (7 - block.Level) * 2); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void Render(ParagraphBlock block) |         private Phrase Render(ParagraphBlock block) | ||||||
|         { |         { | ||||||
|             ColumnText ct = new ColumnText(_Writer.DirectContent); |             return CreateFormatted(block.Inline, Font.HELVETICA, 0, new Color(0, 0, 0), 12); | ||||||
|             ct.AddText(CreateFormatted(block.Inline, Font.HELVETICA, 0, new Color(0, 0, 0), 20)); |  | ||||||
|             ct.Alignment = Element.ALIGN_JUSTIFIED; |  | ||||||
|             ct.SetSimpleColumn(10, 10, 200, 200); |  | ||||||
|             ct.Go(); |  | ||||||
|             //_Document.Add(CreateFormatted(block.Inline, Font.HELVETICA, 0, new Color(0, 0, 0), 20)); |             //_Document.Add(CreateFormatted(block.Inline, Font.HELVETICA, 0, new Color(0, 0, 0), 20)); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -387,6 +387,9 @@ namespace AideDeJeuCmd | ||||||
| 
 | 
 | ||||||
|             var item = await store.GetItemFromDataAsync("spells_hd", "aide"); |             var item = await store.GetItemFromDataAsync("spells_hd", "aide"); | ||||||
| 
 | 
 | ||||||
|  |             using (var context = await StoreViewModel.GetLibraryContextAsync()) | ||||||
|  |             { | ||||||
|  |                 var spells = await context.Spells.ToListAsync(); | ||||||
| 
 | 
 | ||||||
|                 var pdfService = new PdfService(); |                 var pdfService = new PdfService(); | ||||||
|                 //var pc = new AideDeJeu.ViewModels.PlayerCharacter.PlayerCharacterViewModel(); |                 //var pc = new AideDeJeu.ViewModels.PlayerCharacter.PlayerCharacterViewModel(); | ||||||
|  | @ -394,11 +397,13 @@ namespace AideDeJeuCmd | ||||||
|                 using (var stream = new FileStream("test.pdf", FileMode.Create)) |                 using (var stream = new FileStream("test.pdf", FileMode.Create)) | ||||||
|                 { |                 { | ||||||
|                     //pdfService.MarkdownToPdf("# mon titre\n\nhop", stream); |                     //pdfService.MarkdownToPdf("# mon titre\n\nhop", stream); | ||||||
|                 pdfService.MarkdownToPdf(item.Markdown, stream); |                     pdfService.MarkdownToPdf(spells.Select(s => s.Markdown).ToList(), stream); | ||||||
|  |                     //pdfService.MarkdownToPdf(new List<string>() { item.Markdown }, stream); | ||||||
|                     //var stream = new MemoryStream(); |                     //var stream = new MemoryStream(); | ||||||
|                     //pce.GeneratePdfToStream(pc, stream); |                     //pce.GeneratePdfToStream(pc, stream); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         static async Task BuildLibraryAsync() |         static async Task BuildLibraryAsync() | ||||||
|         { |         { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez