MobileDocumentExtensions.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.IO;
  2. using InABox.Avalonia.Platform;
  3. namespace InABox.Avalonia
  4. {
  5. public static class MobileDocumentExtensions
  6. {
  7. public static void ConvertToPDF(this MobileDocument document)
  8. {
  9. document.Data = PlatformTools.PdfRenderer.ImageToPdf(document.Data);
  10. document.FileName = Path.ChangeExtension(document.FileName, "pdf");
  11. // using (var img = new MemoryStream(document.Data))
  12. // {
  13. // var image = new PdfBitmap(img);
  14. //
  15. // var pdfDoc = new PdfDocument();
  16. //
  17. // var section = pdfDoc.Sections.Add();
  18. // section.PageSettings.Margins.All = 0;
  19. // section.PageSettings.Width = image.Width;
  20. // section.PageSettings.Height = image.Height;
  21. //
  22. // var page = section.Pages.Add();
  23. // page.Graphics.DrawImage(image, 0, 0, page.Size.Width, page.Size.Height);
  24. //
  25. // using (var ms = new MemoryStream())
  26. // {
  27. // pdfDoc.Save(ms);
  28. // document.Data = ms.GetBuffer();
  29. // document.FileName = Path.ChangeExtension(document.FileName, "pdf");
  30. // }
  31. // }
  32. }
  33. public static bool IsPDF(this MobileDocument document) => document.FileName.ToUpper().EndsWith(".PDF");
  34. }
  35. }