1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System.IO;
- using InABox.Avalonia.Platform;
- namespace InABox.Avalonia
- {
- public static class MobileDocumentExtensions
- {
- public static void ConvertToPDF(this MobileDocument document)
- {
- document.Data = PlatformTools.PdfRenderer.ImageToPdf(document.Data);
- document.FileName = Path.ChangeExtension(document.FileName, "pdf");
-
- // using (var img = new MemoryStream(document.Data))
- // {
- // var image = new PdfBitmap(img);
- //
- // var pdfDoc = new PdfDocument();
- //
- // var section = pdfDoc.Sections.Add();
- // section.PageSettings.Margins.All = 0;
- // section.PageSettings.Width = image.Width;
- // section.PageSettings.Height = image.Height;
- //
- // var page = section.Pages.Add();
- // page.Graphics.DrawImage(image, 0, 0, page.Size.Width, page.Size.Height);
- //
- // using (var ms = new MemoryStream())
- // {
- // pdfDoc.Save(ms);
- // document.Data = ms.GetBuffer();
- // document.FileName = Path.ChangeExtension(document.FileName, "pdf");
- // }
- // }
- }
-
- public static bool IsPDF(this MobileDocument document) => document.FileName.ToUpper().EndsWith(".PDF");
- }
- }
|