|
@@ -2,6 +2,11 @@ using System;
|
|
|
using System.IO;
|
|
|
using System.Threading.Tasks;
|
|
|
using Plugin.Media;
|
|
|
+using Syncfusion.Drawing;
|
|
|
+using Syncfusion.Pdf;
|
|
|
+using Syncfusion.Pdf.Graphics;
|
|
|
+using Syncfusion.Pdf.Parsing;
|
|
|
+
|
|
|
|
|
|
namespace InABox.Mobile
|
|
|
{
|
|
@@ -9,6 +14,7 @@ namespace InABox.Mobile
|
|
|
public abstract class MobileDocumentSource
|
|
|
{
|
|
|
public abstract Task<MobileDocument> GetDocument();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public class MobileDocumentCameraSource : MobileDocumentSource
|
|
@@ -73,6 +79,37 @@ namespace InABox.Mobile
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static class MobileDocumentExtensions
|
|
|
+ {
|
|
|
+ public static MobileDocument ToPDF(this MobileDocument document)
|
|
|
+ {
|
|
|
+ byte[] result;
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public class MobileDocument
|
|
|
{
|
|
|
public string FileName { get; set; }
|
|
@@ -89,6 +126,5 @@ namespace InABox.Mobile
|
|
|
{
|
|
|
return await new T().GetDocument();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|