From 7a6b5e6bf8a3828787c57c6a3de293a0dc942ed4 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Wed, 5 Jul 2017 23:00:17 +0100 Subject: [PATCH] create PDFExporter project. --- RaceLapTimer/PDFExporter/PDFExporter.csproj | 75 +++++++++++++++++++ RaceLapTimer/PDFExporter/PdfExporter.cs | 45 +++++++++++ .../PDFExporter/Properties/AssemblyInfo.cs | 36 +++++++++ RaceLapTimer/PDFExporter/packages.config | 4 + RaceLapTimer/RaceLapTimer.sln | 9 +++ 5 files changed, 169 insertions(+) create mode 100644 RaceLapTimer/PDFExporter/PDFExporter.csproj create mode 100644 RaceLapTimer/PDFExporter/PdfExporter.cs create mode 100644 RaceLapTimer/PDFExporter/Properties/AssemblyInfo.cs create mode 100644 RaceLapTimer/PDFExporter/packages.config diff --git a/RaceLapTimer/PDFExporter/PDFExporter.csproj b/RaceLapTimer/PDFExporter/PDFExporter.csproj new file mode 100644 index 0000000..4cd92a4 --- /dev/null +++ b/RaceLapTimer/PDFExporter/PDFExporter.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {1752B8A2-C07A-490C-A768-E27B075D3125} + Library + Properties + PDFExporter + PDFExporter + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Syncfusion.HtmlToPdfConverter451.14.1.0.46\lib\net451\Syncfusion.Compression.Base.dll + True + + + ..\packages\Syncfusion.HtmlToPdfConverter451.14.1.0.46\lib\net451\Syncfusion.HtmlConverter.Base.dll + True + + + ..\packages\Syncfusion.HtmlToPdfConverter451.14.1.0.46\lib\net451\Syncfusion.Pdf.Base.dll + True + + + + + + + + + + + + + + + + + {5c6dcc59-19f3-46ad-a479-926610f36257} + Interfaces + + + + + + + + \ No newline at end of file diff --git a/RaceLapTimer/PDFExporter/PdfExporter.cs b/RaceLapTimer/PDFExporter/PdfExporter.cs new file mode 100644 index 0000000..6871e67 --- /dev/null +++ b/RaceLapTimer/PDFExporter/PdfExporter.cs @@ -0,0 +1,45 @@ +using System.IO; +using System.Threading; +using Interfaces; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +namespace PDFExporter +{ + public class PdfExporter:IFileExporter + { + private Stream str = new MemoryStream(); + public Stream Export(string fileContent, string baseUrl) + { + var t = new Thread(()=>DoExport(fileContent, baseUrl)); + t.SetApartmentState(ApartmentState.STA); + t.Start(); + t.Join(); + return str; + } + + public ExportProviderDetails GetDetails() + { + return new ExportProviderDetails + { + Type = "PDF" + }; + } + + void DoExport(string fileContent, string baseUrl) + { + var pdfExporter = new HtmlToPdfConverter(); + var settings = new IEConverterSettings(); + settings.AdditionalDelay = 2000; + pdfExporter.ConverterSettings = settings; + PdfDocument doc = pdfExporter.Convert(fileContent, baseUrl); + MemoryStream ms = new MemoryStream(); + doc.Save(ms); + doc.Close(true); + ms.CopyTo(str); + ms.Flush(); + ms.Close(); + ms.Dispose(); + } + } +} diff --git a/RaceLapTimer/PDFExporter/Properties/AssemblyInfo.cs b/RaceLapTimer/PDFExporter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6a6d997 --- /dev/null +++ b/RaceLapTimer/PDFExporter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PDFExporter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PDFExporter")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1752b8a2-c07a-490c-a768-e27b075d3125")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/RaceLapTimer/PDFExporter/packages.config b/RaceLapTimer/PDFExporter/packages.config new file mode 100644 index 0000000..2e6f618 --- /dev/null +++ b/RaceLapTimer/PDFExporter/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer.sln b/RaceLapTimer/RaceLapTimer.sln index 8be1aaa..c7e3c3d 100644 --- a/RaceLapTimer/RaceLapTimer.sln +++ b/RaceLapTimer/RaceLapTimer.sln @@ -21,6 +21,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Logger", "Logger", "{36BDEE EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IrDaemonNotifier", "IrDaemonNotifier\IrDaemonNotifier.csproj", "{916994F6-1711-4AEB-8DE6-4AB6FCB3F080}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FileExporters", "FileExporters", "{01615648-0CA9-41C5-8E28-8B8A6B84A215}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFExporter", "PDFExporter\PDFExporter.csproj", "{1752B8A2-C07A-490C-A768-E27B075D3125}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +59,10 @@ Global {916994F6-1711-4AEB-8DE6-4AB6FCB3F080}.Debug|Any CPU.Build.0 = Debug|Any CPU {916994F6-1711-4AEB-8DE6-4AB6FCB3F080}.Release|Any CPU.ActiveCfg = Release|Any CPU {916994F6-1711-4AEB-8DE6-4AB6FCB3F080}.Release|Any CPU.Build.0 = Release|Any CPU + {1752B8A2-C07A-490C-A768-E27B075D3125}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1752B8A2-C07A-490C-A768-E27B075D3125}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1752B8A2-C07A-490C-A768-E27B075D3125}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1752B8A2-C07A-490C-A768-E27B075D3125}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -63,5 +71,6 @@ Global {9A93A12F-7591-406A-A4F3-41AA8299C4B4} = {36BDEE78-985C-4AF5-A39B-3BE89FAEB281} {734097B0-A764-40AD-957A-43FE4F085B65} = {CDAC76D5-5EC6-4357-A27C-0095BF98FDDF} {916994F6-1711-4AEB-8DE6-4AB6FCB3F080} = {CDAC76D5-5EC6-4357-A27C-0095BF98FDDF} + {1752B8A2-C07A-490C-A768-E27B075D3125} = {01615648-0CA9-41C5-8E28-8B8A6B84A215} EndGlobalSection EndGlobal