mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	This commit is contained in:
		
							parent
							
								
									cf9f5357a0
								
							
						
					
					
						commit
						c0633ba6e9
					
				
					 4 changed files with 24 additions and 10 deletions
				
			
		|  | @ -10,6 +10,7 @@ using System.Diagnostics; | |||
| using System.IO; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using Xamarin.Forms; | ||||
| 
 | ||||
| namespace AideDeJeu.Pdf | ||||
|  | @ -39,6 +40,25 @@ namespace AideDeJeu.Pdf | |||
| 
 | ||||
|         Document _Document = null; | ||||
|         PdfWriter _Writer = null; | ||||
| 
 | ||||
|         public string BasePdfDirectory | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, "pdf"); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public async Task<string> MarkdownToPDF(List<string> mds) | ||||
|         { | ||||
|             var basePath = BasePdfDirectory; | ||||
|             Directory.CreateDirectory(basePath); | ||||
|             using (var stream = new FileStream(Path.Combine(BasePdfDirectory, "test.pdf"), FileMode.Create)) | ||||
|             { | ||||
|                 MarkdownToPdf(mds, stream); | ||||
|             } | ||||
|             return "test.pdf"; | ||||
|         } | ||||
|         public void MarkdownToPdf(List<string> mds, Stream stream) | ||||
|         { | ||||
|             var pipeline = new Markdig.MarkdownPipelineBuilder().UseYamlFrontMatter().UsePipeTables().Build(); | ||||
|  |  | |||
|  | @ -363,15 +363,9 @@ namespace AideDeJeu.ViewModels | |||
| 
 | ||||
|         public async Task ExecuteGeneratePDFCommandAsync(string markdown) | ||||
|         { | ||||
|             using (var stream = new FileStream(Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, Path.Combine("pdf", "test.pdf")), FileMode.Create)) | ||||
|             { | ||||
| 
 | ||||
|                 PdfService.Instance.MarkdownToPdf(new List<string>() { markdown }, stream); | ||||
|             } | ||||
| 
 | ||||
|             var page = new PdfViewPage(); | ||||
|             page.PdfFile = new Tools.NotifyTaskCompletion<string>(Task.Run(() => | ||||
|                 { return "test.pdf"; } | ||||
|             page.PdfFile = new Tools.NotifyTaskCompletion<string>(Task.Run(async() => | ||||
|                 { return await PdfService.Instance.MarkdownToPDF(new List<string>() { markdown }); } | ||||
|             )); | ||||
|             page.BindingContext = page; | ||||
|             await Navigation.PushAsync(page, true); | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ | |||
|         </ResourceDictionary> | ||||
|     </ContentPage.Resources> | ||||
|     <ContentPage.ToolbarItems> | ||||
|         <ToolbarItem Name="Print" Text="Générer un PDF" Order="Primary" Icon="round_star.png" Command="{Binding Main.Navigator.GeneratePDFCommand}" CommandParameter="{Binding Item.Markdown}" /> | ||||
|         <ToolbarItem Name="Print" Text="Générer un PDF" Order="Secondary" Icon="round_star.png" Command="{Binding Main.Navigator.GeneratePDFCommand}" CommandParameter="{Binding Item.Markdown}" /> | ||||
|         <ToolbarItem Name="AddToFavorites" Text="Ajouter aux favoris" Order="Primary" Icon="round_star.png" Command="{Binding Main.Navigator.AddToFavoritesCommand}" /> | ||||
|     </ContentPage.ToolbarItems> | ||||
|     <Grid> | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ | |||
|         </ResourceDictionary> | ||||
|     </ContentPage.Resources> | ||||
|     <ContentPage.ToolbarItems> | ||||
|         <ToolbarItem Name="Print" Text="Générer un PDF" Order="Primary" Icon="round_star.png" Command="{Binding Main.Navigator.GeneratePDFCommand}" CommandParameter="{Binding BindingContext.Items.Markdown, Source={x:Reference This}}" /> | ||||
|         <ToolbarItem Name="Print" Text="Générer un PDF" Order="Secondary" Icon="round_star.png" Command="{Binding Main.Navigator.GeneratePDFCommand}" CommandParameter="{Binding BindingContext.Items.Markdown, Source={x:Reference This}}" /> | ||||
|         <ToolbarItem Name="AddToFavorites" Text="Ajouter aux favoris" Order="Primary" Icon="round_star.png" Command="{Binding Main.Navigator.AddToFavoritesCommand}" /> | ||||
|     </ContentPage.ToolbarItems> | ||||
|     <Grid> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez