From 3033907118edb3ca7259db34a5afd4834805bc8c Mon Sep 17 00:00:00 2001 From: jeyalakshmit Date: Wed, 27 Sep 2023 10:52:43 +0530 Subject: [PATCH] Added the HTML to PDF sample --- .../.NET/Inject_custom_CSS_to_HTML.sln | 25 +++++++++++++ .../Inject_custom_CSS_to_HTML.csproj | 14 ++++++++ .../.NET/Inject_custom_CSS_to_HTML/Program.cs | 23 ++++++++++++ .../.NET/Inject_custom_JavaScript_to_HTML.sln | 25 +++++++++++++ .../Inject_custom_JavaScript_to_HTML.csproj | 14 ++++++++ .../Program.cs | 28 +++++++++++++++ .../.NET/Optimize-HTML-to-PDF-performance.sln | 25 +++++++++++++ .../Optimize-HTML-to-PDF-performance.csproj | 15 ++++++++ .../Program.cs | 36 +++++++++++++++++++ .../.NET/Set_blink_path_in_HTML_to_PDF.sln | 25 +++++++++++++ .../Set_blink_path_in_HTML_to_PDF/Program.cs | 20 +++++++++++ .../Set_blink_path_in_HTML_to_PDF.csproj | 14 ++++++++ 12 files changed, 264 insertions(+) create mode 100644 HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML.sln create mode 100644 HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Inject_custom_CSS_to_HTML.csproj create mode 100644 HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Program.cs create mode 100644 HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML.sln create mode 100644 HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Inject_custom_JavaScript_to_HTML.csproj create mode 100644 HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Program.cs create mode 100644 HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance.sln create mode 100644 HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Optimize-HTML-to-PDF-performance.csproj create mode 100644 HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Program.cs create mode 100644 HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF.sln create mode 100644 HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Program.cs create mode 100644 HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Set_blink_path_in_HTML_to_PDF.csproj diff --git a/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML.sln b/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML.sln new file mode 100644 index 00000000..217dafdf --- /dev/null +++ b/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32819.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inject_custom_CSS_to_HTML", "Inject_custom_CSS_to_HTML\Inject_custom_CSS_to_HTML.csproj", "{A00BDA8D-F1AB-4CB0-B97D-9A80631F6BB4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A00BDA8D-F1AB-4CB0-B97D-9A80631F6BB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A00BDA8D-F1AB-4CB0-B97D-9A80631F6BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A00BDA8D-F1AB-4CB0-B97D-9A80631F6BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A00BDA8D-F1AB-4CB0-B97D-9A80631F6BB4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FC291101-A10D-4F23-8A31-BDC2251AE445} + EndGlobalSection +EndGlobal diff --git a/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Inject_custom_CSS_to_HTML.csproj b/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Inject_custom_CSS_to_HTML.csproj new file mode 100644 index 00000000..5475acba --- /dev/null +++ b/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Inject_custom_CSS_to_HTML.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Program.cs b/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Program.cs new file mode 100644 index 00000000..9b09e9ec --- /dev/null +++ b/HTML to PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Program.cs @@ -0,0 +1,23 @@ +// See https://aka.ms/new-console-template for more information + +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the Blink viewport size. +blinkConverterSettings.ViewPortSize = new Size(1280, 0); +blinkConverterSettings.Margin.All = 30; +//Set the custom CSS +blinkConverterSettings.Css = "body {\r\n background-color: lightyellow; \r\n}"; +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert the URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Create file stream. +FileStream fileStream = new FileStream("../../../HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); +//Save and close the PDF document. +document.Save(fileStream); +document.Close(true); \ No newline at end of file diff --git a/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML.sln b/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML.sln new file mode 100644 index 00000000..32879461 --- /dev/null +++ b/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32819.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inject_custom_JavaScript_to_HTML", "Inject_custom_JavaScript_to_HTML\Inject_custom_JavaScript_to_HTML.csproj", "{634C42CC-B7A6-406F-AC6B-50E5D9FCEF7C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {634C42CC-B7A6-406F-AC6B-50E5D9FCEF7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {634C42CC-B7A6-406F-AC6B-50E5D9FCEF7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {634C42CC-B7A6-406F-AC6B-50E5D9FCEF7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {634C42CC-B7A6-406F-AC6B-50E5D9FCEF7C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CF5A3C10-D91E-4031-83C3-D3D28685BCEB} + EndGlobalSection +EndGlobal diff --git a/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Inject_custom_JavaScript_to_HTML.csproj b/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Inject_custom_JavaScript_to_HTML.csproj new file mode 100644 index 00000000..5475acba --- /dev/null +++ b/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Inject_custom_JavaScript_to_HTML.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Program.cs b/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Program.cs new file mode 100644 index 00000000..dc93e16e --- /dev/null +++ b/HTML to PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Program.cs @@ -0,0 +1,28 @@ +// See https://aka.ms/new-console-template for more information + +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using System.IO; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +//Initialize the blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the Blink viewport size. +blinkConverterSettings.ViewPortSize = new Size(1280, 0); +blinkConverterSettings.Margin.All = 30; + +//Set the Custom JavaScript +blinkConverterSettings.JavaScript = "document.querySelectorAll('img').forEach((node)=>{node.remove();})"; +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert the URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + +//Create a filestream. +FileStream fileStream = new FileStream("../../../HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); +//Save and close the PDF document. +document.Save(fileStream); +document.Close(true); diff --git a/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance.sln b/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance.sln new file mode 100644 index 00000000..c22d9ad0 --- /dev/null +++ b/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32819.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Optimize-HTML-to-PDF-performance", "Optimize-HTML-to-PDF-performance\Optimize-HTML-to-PDF-performance.csproj", "{4613D841-222D-4A43-A27F-AA8C29A6F195}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4613D841-222D-4A43-A27F-AA8C29A6F195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4613D841-222D-4A43-A27F-AA8C29A6F195}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4613D841-222D-4A43-A27F-AA8C29A6F195}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4613D841-222D-4A43-A27F-AA8C29A6F195}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4F1700C7-9DA0-47F7-94D0-7C97A709821A} + EndGlobalSection +EndGlobal diff --git a/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Optimize-HTML-to-PDF-performance.csproj b/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Optimize-HTML-to-PDF-performance.csproj new file mode 100644 index 00000000..44b942e7 --- /dev/null +++ b/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Optimize-HTML-to-PDF-performance.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + Optimize_HTML_to_PDF_performance + enable + enable + + + + + + + diff --git a/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Program.cs b/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Program.cs new file mode 100644 index 00000000..1a2b4fad --- /dev/null +++ b/HTML to PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Program.cs @@ -0,0 +1,36 @@ +// See https://aka.ms/new-console-template for more information + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using System.IO; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Reuse the browser instance. +htmlConverter.ReuseBrowserProcess = true; + +//Create PDF document. +PdfDocument document = new PdfDocument(); +//Create memory stream. +MemoryStream memoryStream = new MemoryStream(); + +for (int i = 0; i < 10; i++) +{ + //Initialize the blink converter settings. + BlinkConverterSettings settings = new BlinkConverterSettings(); + settings.AdditionalDelay = 1000; + settings.EnableJavaScript = true; + //Assign the settings to HTML converter. + htmlConverter.ConverterSettings = settings; + + //Convert the URL to PDF document. + document = htmlConverter.Convert("https://www.google.com"); + + //Save and close the PDF document. + document.Save(memoryStream); + document.Close(true); + File.WriteAllBytes("ReuseBrowserProcess" + Guid.NewGuid().ToString() + ".pdf", memoryStream.ToArray()); +} + +//Close HTML converter. +htmlConverter.Close(); diff --git a/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF.sln b/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF.sln new file mode 100644 index 00000000..5abf8078 --- /dev/null +++ b/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32819.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Set_blink_path_in_HTML_to_PDF", "Set_blink_path_in_HTML_to_PDF\Set_blink_path_in_HTML_to_PDF.csproj", "{DCE10516-E8CB-4FE2-9AF2-6AFF2DE04026}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DCE10516-E8CB-4FE2-9AF2-6AFF2DE04026}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DCE10516-E8CB-4FE2-9AF2-6AFF2DE04026}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DCE10516-E8CB-4FE2-9AF2-6AFF2DE04026}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DCE10516-E8CB-4FE2-9AF2-6AFF2DE04026}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A2535A2F-9E26-4961-88B6-733DDA34D313} + EndGlobalSection +EndGlobal diff --git a/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Program.cs b/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Program.cs new file mode 100644 index 00000000..0e606469 --- /dev/null +++ b/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Program.cs @@ -0,0 +1,20 @@ +// See https://aka.ms/new-console-template for more information + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set Blink binaries path. +blinkConverterSettings.BlinkPath = @"../../../BlinkBinaries/"; +//Assign Blink converter settings to HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + +//Create file stream to save the PDF document. +FileStream fileStream = new FileStream("../../../HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); +//Save and close the PDF document. +document.Save(fileStream); +document.Close(true); diff --git a/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Set_blink_path_in_HTML_to_PDF.csproj b/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Set_blink_path_in_HTML_to_PDF.csproj new file mode 100644 index 00000000..5475acba --- /dev/null +++ b/HTML to PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Set_blink_path_in_HTML_to_PDF.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + +