diff --git a/Document-Processing/Data-Extraction/OCR/NET/overview.md b/Document-Processing/Data-Extraction/OCR/NET/overview.md index fa050f0c11..bf3739533d 100644 --- a/Document-Processing/Data-Extraction/OCR/NET/overview.md +++ b/Document-Processing/Data-Extraction/OCR/NET/overview.md @@ -43,5 +43,5 @@ N> Starting with v20.1.0.x, if you reference Syncfusion® OCR proc * Image into searchable PDF or PDF/A. * Improved accessibility. * Post-processing. -* Compatible with .NET Framework 4.5 and above. +* Compatible with .NET Framework 4.6.2 and above. * Compatible with .NET Core 2.0 and above. diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Converting-HTML-to-PDF.md b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Converting-HTML-to-PDF.md index b07c9fa654..2eae3784de 100644 --- a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Converting-HTML-to-PDF.md +++ b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Converting-HTML-to-PDF.md @@ -7,7 +7,7 @@ documentation: UG --- # Converting HTML to PDF -The HTML to PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML files to PDF using C#. It uses popular rendering engines such as Blink (Google Chrome) and is reliable and accurate. The result preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage. +The [HTML to PDF converter](https://www.syncfusion.com/document-sdk/net-pdf-library/html-to-pdf) is a .NET library for converting webpages, SVG, MHTML, and HTML files to PDF using C#. It uses popular rendering engines such as Blink (Google Chrome) and is reliable and accurate. The result preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage. Syncfusion® HTML-to-PDF converter will work seamlessly in various platforms like Azure Cloud or web apps, Azure Functions, Amazon Web Service (AWS), Docker, WinForms, WPF, ASP.NET MVC, ASP.NET Core with Windows, Linux, and macOS. @@ -200,8 +200,6 @@ using Syncfusion.HtmlConverter; Step 4: Use the following code sample to convert the URL to PDF in the program.cs. -{% tabs %} - {% highlight c# tabtitle="C#" %} //Initialize HTML to PDF converter. @@ -221,8 +219,6 @@ document.Close(true); {% endhighlight %} -{% endtabs %} - By executing the program, you will get the PDF document as follows. htmltopdfoutput @@ -271,8 +267,6 @@ By default, the PDF document generated with the IE rendering engine comes with t IEWarning Please refer to the below code snippet to use the DisableIEWarning API to remove the default IE warning from the PDF document. -{% tabs %} - {% highlight c# tabtitle="C#" %} //Initialize the HTML to PDF converter @@ -291,27 +285,4 @@ document.Close(true); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} -'Initialize the HTML to PDF converter -Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.IE) -Dim settings As New IEConverterSettings() -'Disable Default IE Warning Message -settings.DisableIEWarning = true -'Assign IE settings to HTML converter -htmlConverter.ConverterSettings = settings -'Convert URL to PDF -Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") - -'Save and close the PDF document -document.Save("Output.pdf") -document.Close(True) - -{% endhighlight %} - -{% highlight c# tabtitle="ASP.NET Core" %} -//Currently, IE rendering engine does not support conversion in .NET Core platform -{% endhighlight %} - -{% endtabs %} - N>Please try our [Blink](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/net-core) engine to improve the quality and accuracy of the HTML to PDF conversion. diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md index ebf3a7b0a5..8f894b1a59 100644 --- a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md +++ b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md @@ -28,6 +28,21 @@ PdfDocument document = htmlConverter.Convert("https://www.google.com"); document.Save("Output.pdf"); document.Close(true); +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); {% endhighlight %} @@ -69,8 +84,29 @@ To convert the HTML string to PDF using [Convert](https://help.syncfusion.com/cr {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Convert-the-HTML-string-to-PDF-document/.NET/Convert-the-HTML-string-to-PDF-document/Program.cs, 300" %} -using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.HtmlConverter; + +//Initialize HTML to PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +//HTML string and Base URL +string htmlText = "\"Syncfusion_logo\"

Hello World

"; +string baseUrl = @"C:/Temp/HTMLFiles/"; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert(htmlText, baseUrl); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -108,16 +144,6 @@ document.Close(True) {% endhighlight %} -{% highlight html %} - - -Syncfusion_logo -

Hello World

- - - -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Convert-the-HTML-string-to-PDF-document). @@ -247,17 +273,6 @@ File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData) {% endhighlight %} -{% highlight html %} - - - - Syncfusion_logo -

Hello World

- - - -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Convert-the-HTML-string-to-image-file). @@ -286,7 +301,29 @@ Image image = htmlConverter.ConvertToImage(svg, ""); byte[] imageBytes = image.ImageData; // Save the image data to a file in JPEG format -File.WriteAllBytes("Output.jpg"), imageBytes); +File.WriteAllBytes("Output.jpg", imageBytes); + +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using Syncfusion.HtmlConverter; + +// Create an instance of the Syncfusion HtmlToPdfConverter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +// Read the SVG content from a file +string svg = File.ReadAllText("sample.svg"); + +// Convert the SVG content to an image using the converter +Image[] image = htmlConverter.ConvertToImage(svg, ""); + +// Save the image data to a file in JPEG format +for (int i = 0; i < image.Length; i++) +{ + image[i].Save($"Output_{i}.jpg", ImageFormat.Jpeg); +} {% endhighlight %} @@ -345,6 +382,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Disable JavaScript; By default, true +blinkConverterSettings.EnableJavaScript = false; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -402,6 +462,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +// Set additional delay; units in milliseconds +blinkConverterSettings.AdditionalDelay = 3000; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -458,6 +541,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Enable hyperlinks; By default - true +blinkConverterSettings.EnableHyperLink = false; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -516,6 +622,29 @@ document.Save("Output.pdf"); document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set enable bookmarks +settings.EnableBookmarks = true; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert HTML to PDF +PdfDocument document = htmlConverter.Convert("input.html"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -537,50 +666,6 @@ document.Save("Output.pdf") document.Close(True) {% endhighlight %} - -{% highlight html %} - - - - - - - -

Syncfusion®

- -

Introduction

- Syncfusion® is the enterprise technology partner of choice for software development, delivering a broad range of web, mobile, and desktop controls coupled with a service-oriented approach throughout the entire application life cycle. -

Products

-

WEB

- The most comprehensive suite for enterprise web development. -

Desktop

- Comprehensive suite of over 115 components including the fastest chart and grid components. -

Mobile

- Comprehensive suite of components for Xamarin.iOS, Xamarin.Android and Xamarin.Forms including the fastest chart and grid. -

Consulting

- We can build web, mobile, and desktop applications better and faster than anyone since we build on top of our award-winning suite of components and frameworks, saving you time and money. -

Company

-

About us

- Syncfusion® has established itself as the trusted partner worldwide for use in mission-critical applications. Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion® has more than 12,000 customers, including large financial institutions, Fortune 100 companies, and global IT consultancies. -

contact us

- Morrisville Office - Company Headquarters - 2501 Aerial Center Parkway - Suite 200 - Morrisville, NC 27560 - USA - - - -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Creating-bookmarks-while-converting-HTML-to-PDF). @@ -618,6 +703,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set enable table of contents +settings.EnableToc = true; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert HTML to PDF +PdfDocument document = htmlConverter.Convert("input.html"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -640,49 +748,6 @@ document.Close(True) {% endhighlight %} -{% highlight html %} - - - - - - - -

Syncfusion®

- -

Introduction

- Syncfusion® is the enterprise technology partner of choice for software development, delivering a broad range of web, mobile, and desktop controls coupled with a service-oriented approach throughout the entire application life cycle. -

Products

-

WEB

- The most comprehensive suite for enterprise web development. -

Desktop

- Comprehensive suite of over 115 components including the fastest chart and grid components. -

Mobile

- Comprehensive suite of components for Xamarin.iOS, Xamarin.Android and Xamarin.Forms including the fastest chart and grid. -

Consulting

- We can build web, mobile, and desktop applications better and faster than anyone since we build on top of our award-winning suite of components and frameworks, saving you time and money. -

Company

-

About us

- Syncfusion® has established itself as the trusted partner worldwide for use in mission-critical applications. Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion® has more than 12,000 customers, including large financial institutions, Fortune 100 companies, and global IT consultancies. -

contact us

- Morrisville Office - Company Headquarters - 2501 Aerial Center Parkway - Suite 200 - Morrisville, NC 27560 - USA - - - -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Create-TOC-while-converting-HTML-to-PDF). @@ -728,6 +793,39 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.HtmlToPdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set enable table of contents +settings.EnableToc = true; +//Set the style for level 1(H1) items in table of contents +HtmlToPdfTocStyle tocstyleH1 = new HtmlToPdfTocStyle(); +tocstyleH1.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Regular); +tocstyleH1.BackgroundColor = new PdfSolidBrush(new PdfColor(Color.FromArgb(68, 114, 196))); +tocstyleH1.ForeColor = PdfBrushes.White; +tocstyleH1.Padding = new PdfPaddings(5, 5, 3, 3); +settings.Toc.SetItemStyle(1, tocstyleH1); +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert HTML to PDF +PdfDocument document = htmlConverter.Convert("input.html"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.Drawing @@ -759,50 +857,6 @@ document.Save("Output.pdf") document.Close(True) {% endhighlight %} - -{% highlight html %} - - - - - - - -

Syncfusion®

- -

Introduction

- Syncfusion® is the enterprise technology partner of choice for software development, delivering a broad range of web, mobile, and desktop controls coupled with a service-oriented approach throughout the entire application life cycle. -

Products

-

WEB

- The most comprehensive suite for enterprise web development. -

Desktop

- Comprehensive suite of over 115 components including the fastest chart and grid components. -

Mobile

- Comprehensive suite of components for Xamarin.iOS, Xamarin.Android and Xamarin.Forms including the fastest chart and grid. -

Consulting

- We can build web, mobile, and desktop applications better and faster than anyone since we build on top of our award-winning suite of components and frameworks, saving you time and money. -

Company

-

About us

- Syncfusion® has established itself as the trusted partner worldwide for use in mission-critical applications. Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion® has more than 12,000 customers, including large financial institutions, Fortune 100 companies, and global IT consultancies. -

contact us

- Morrisville Office - Company Headquarters - 2501 Aerial Center Parkway - Suite 200 - Morrisville, NC 27560 - USA - - - -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Create-custom-style-TOC-when-converting-HTML-to-PDF). @@ -854,28 +908,69 @@ htmlConverter.Close(); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} -Imports Syncfusion.Drawing -Imports Syncfusion.HtmlConverter -Imports Syncfusion.Pdf +using System.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; -' Create an instance of HTML-to-PDF converter -Dim htmlConverter As New HtmlToPdfConverter() -' Configure Blink converter settings -Dim blinkConverterSettings As New BlinkConverterSettings() With { - .ViewPortSize = New Size(1280, 0), ' Set viewport width for rendering - .EnableToc = True ' Enable Table of Contents (TOC) -} -' Set TOC starting page number to skip the cover page -blinkConverterSettings.Toc.StartingPageNumber = 1 -' Apply the settings to the converter -htmlConverter.ConverterSettings = blinkConverterSettings -' Read the main HTML content and convert it to PDF -Dim inputhtml As String = File.ReadAllText("input.html") -Dim document As PdfDocument = htmlConverter.Convert(inputhtml, "") -' Create cover page and insert to the 0th index. -' Apply scaling settings for the cover page +// Create an instance of HTML-to-PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +// Configure Blink converter settings +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings() +{ + ViewPortSize = new Size(1280, 0), // Set viewport width for rendering + EnableToc = true, // Enable Table of Contents (TOC) +}; +// Set TOC starting page number to skip the cover page +blinkConverterSettings.Toc.StartingPageNumber = 1; +// Apply the settings to the converter +htmlConverter.ConverterSettings = blinkConverterSettings; +// Read the main HTML content and convert it to PDF +string inputhtml = File.ReadAllText("input.html"); +PdfDocument document = htmlConverter.Convert(inputhtml, ""); +//Create cover page and insert to the 0th index. +// Apply scaling settings for the cover page +htmlConverter.ConverterSettings = new BlinkConverterSettings() +{ + Scale = 1.5f +}; +// Convert the cover page HTML to PDF +string coverimage = File.ReadAllText("coverpage.html"); +PdfDocument coverPage = htmlConverter.Convert(coverimage, ""); +// Insert the cover page at the beginning of the main document +document.Pages.Insert(0, coverPage.Pages[0]); +// Save the PDF document +document.Save("Output.pdf"); +//Dispose the document +coverPage.Close(true); +document.Close(true); +htmlConverter.Close(); + +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Drawing +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + +' Create an instance of HTML-to-PDF converter +Dim htmlConverter As New HtmlToPdfConverter() +' Configure Blink converter settings +Dim blinkConverterSettings As New BlinkConverterSettings() With { + .ViewPortSize = New Size(1280, 0), ' Set viewport width for rendering + .EnableToc = True ' Enable Table of Contents (TOC) +} +' Set TOC starting page number to skip the cover page +blinkConverterSettings.Toc.StartingPageNumber = 1 +' Apply the settings to the converter +htmlConverter.ConverterSettings = blinkConverterSettings +' Read the main HTML content and convert it to PDF +Dim inputhtml As String = File.ReadAllText("input.html") +Dim document As PdfDocument = htmlConverter.Convert(inputhtml, "") +' Create cover page and insert to the 0th index. +' Apply scaling settings for the cover page htmlConverter.ConverterSettings = New BlinkConverterSettings() With { .Scale = 1.5F } @@ -926,6 +1021,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set print media type +blinkConverterSettings.MediaType = MediaType.Print; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -983,6 +1101,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set enable form +settings.EnableForm = true; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1038,6 +1179,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +// Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +blinkConverterSettings.Username = "username"; +blinkConverterSettings.Password = "password"; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.example.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1094,6 +1258,30 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +// Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +// Add cookies as name and value pair +blinkConverterSettings.Cookies.Add("CookieName1", " CookieValue1"); +blinkConverterSettings.Cookies.Add("CookieName2", " CookieValue2"); +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.example.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1150,6 +1338,30 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize HTML to PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Add a bearer token to login a webpage +settings.HttpRequestHeaders.Add("Authorization", "bearer <>"); +//Assign Blink settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.example.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1209,6 +1421,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + +//Enable offline mode +blinkConverterSettings.EnableOfflineMode = true; + +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; +string inputHTML = Path.GetFullPath("input.html"); +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert(inputHTML); +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1267,6 +1502,30 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Add HTTP post parameters to HttpPostFields +settings.HttpPostFields.Add("firstName", "Andrew"); +settings.HttpPostFields.Add("lastName", "Fuller"); +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.example.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1321,6 +1580,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +string url = "https://www.example.com"; +Uri getMethodUri = new Uri(url); +string httpGetData = getMethodUri.Query.Length > 0 ? "&" : "?" + String.Format("{0}={1}", "firstName", "Andrew"); +httpGetData += String.Format("&{0}={1}", "lastName", "Fuller"); +string urlToConvert = url + httpGetData; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert(urlToConvert); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1392,6 +1674,31 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set manual proxy settings +settings.ProxySettings.HostName = "127.0.0.1"; +settings.ProxySettings.PortNumber = 8080; +settings.ProxySettings.Type = BlinkProxyType.Http; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1451,6 +1758,30 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set Blink viewport size +blinkConverterSettings.ViewPortSize = new Size(800, 0); +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports System.Drawing @@ -1501,6 +1832,23 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +//Convert Partial webpage to PDF +PdfDocument document = htmlConverter.ConvertPartialHtml("input.html", "pic"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1516,26 +1864,6 @@ document.Save("Output.pdf") document.Close(True) {% endhighlight %} - -{% highlight html %} - - - - - -Hello world -
- Smiley face
- This is a Syncfusion Logo -
-
- Hello world -
- - - -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Convert-partial-webpage-to-PDF-document). @@ -1577,6 +1905,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set singlePageLayout option to render the whole HTML content in a single PDF page +settings.SinglePageLayout = SinglePageLayout.FitWidth; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = settings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1628,6 +1979,27 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +PdfLayoutResult layoutResult = null; +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com", out layoutResult); +//Draw the text at the end of HTML content +PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 11); +document.Pages[document.Pages.Count - 1].Graphics.DrawString("End of HTML content", font, PdfBrushes.Red, new PointF(0, layoutResult.Bounds.Bottom)); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1685,6 +2057,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +// Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set windows status +blinkConverterSettings.WindowStatus = "completed"; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("input.html"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1707,26 +2102,6 @@ document.Close(True) {% endhighlight %} -{% highlight html %} - - - - - -
- Wait for 2 Seconds -
- - - - -{% endhighlight %} - {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Set-windows-status-while-converting-HTML-to-PDF). @@ -1760,6 +2135,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the page size. +blinkConverterSettings.PdfPageSize = PdfPageSize.A4; +//Assign Blink converter settings to HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save the PDF document. +document.Save("Output.pdf"); +//Close the document. +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1814,6 +2212,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the margin. +blinkConverterSettings.Margin.All = 50; +//Assign Blink converter settings to HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save the PDF document +document.Save("Output.pdf"); +//Close the document. +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -1829,23 +2250,67 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") -'Save and close the PDF document. -document.Save("Output.pdf") -document.Close(True) +'Save and close the PDF document. +document.Save("Output.pdf") +document.Close(True) + +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/HTML-to-PDF-margin-customization). + +## Header and footer + +To set the header and footer when converting HTML to PDF, utilize the [PdfHeader](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_PdfHeader) and [PdfFooter](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_PdfFooter) properties in the [BlinkConverterSettings](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class. Please refer to the following code example. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-Header-and-footer/.NET/HTML-to-PDF-Header-and-footer/Program.cs, 300" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Create PDF page template element for header with bounds. +PdfPageTemplateElement header = new PdfPageTemplateElement(new RectangleF(0, 0, blinkConverterSettings.PdfPageSize.Width, 50)); +//Create font and brush for header element. +PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7); +PdfBrush brush = new PdfSolidBrush(Color.Black); +//Draw the header string in header template element. +header.Graphics.DrawString("This is header", font, brush, PointF.Empty); +//Assign the header element to PdfHeader of Blink converter settings. +blinkConverterSettings.PdfHeader = header; +//Create PDF page template element for footer with bounds. +PdfPageTemplateElement footer = new PdfPageTemplateElement(new RectangleF(0, 0, blinkConverterSettings.PdfPageSize.Width, 50)); +//Create page number field. +PdfPageNumberField pageNumber = new PdfPageNumberField(font, PdfBrushes.Black); +//Create page count field. +PdfPageCountField count = new PdfPageCountField(font, PdfBrushes.Black); +//Add the fields in composite fields. +PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Black, "Page {0} of {1}", pageNumber, count); +//Draw the composite field in footer +compositeField.Draw(footer.Graphics, PointF.Empty); +//Assign the footer element to PdfFooter of Blink converter settings. +blinkConverterSettings.PdfFooter = footer; +//Set Blink viewport size. +blinkConverterSettings.ViewPortSize = new Size(1024, 0); +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF. +PdfDocument document = htmlConverter.Convert("https://www.google.com/"); + +//Save a PDF document +document.Save("Output.pdf"); +//Close the document. +document.Close(true); {% endhighlight %} -{% endtabs %} - -You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/HTML-to-PDF-margin-customization). - -## Header and footer - -To set the header and footer when converting HTML to PDF, utilize the [PdfHeader](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_PdfHeader) and [PdfFooter](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_PdfFooter) properties in the [BlinkConverterSettings](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class. Please refer to the following code example. - -{% tabs %} - -{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-Header-and-footer/.NET/HTML-to-PDF-Header-and-footer/Program.cs, 300" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} using Syncfusion.HtmlConverter; using Syncfusion.Pdf.Graphics; @@ -1966,6 +2431,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the Orientation. +blinkConverterSettings.Orientation = PdfPageOrientation.Landscape; +//Assign Blink converter settings to HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save a PDF document. +document.Save("Output.pdf"); +//Close the document. +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2020,6 +2508,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the page rotate. +blinkConverterSettings.PageRotateAngle = PdfPageRotateAngle.RotateAngle90; +//Assign Blink converter settings to the HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save a PDF document +document.Save("Output.pdf"); +//Close the document. +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2082,6 +2593,37 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the Blink viewport size. +blinkConverterSettings.ViewPortSize = new Size(1280, 0); +//Set the html margin-top value based on the html header height and margin-top value. +blinkConverterSettings.Margin.Top = 70; +//Set the html margin-bottom value based on the html footer height and margin-bottom value. +blinkConverterSettings.Margin.Bottom = 40; +//Set the custom HTML header to add at the top of each page. +blinkConverterSettings.HtmlHeader = File.ReadAllText("header.html"); +//Set the custom HTML footer to add at the bottom of each page. +blinkConverterSettings.HtmlFooter = File.ReadAllText("footer.html"); +//Assign Blink converter settings to the HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert the URL to a PDF document. +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + +//Save and close a PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2151,6 +2693,30 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.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: red; \r\n}"; +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert the URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2211,6 +2777,30 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.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 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"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2278,6 +2868,37 @@ htmlConverter.Close(); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Reuse the browser instance. +htmlConverter.ReuseBrowserProcess = true; +//Create PDF document. +PdfDocument document = new PdfDocument(); + +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("Output.pdf"); + document.Close(true); +} +//Close HTML converter. +htmlConverter.Close(); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2347,6 +2968,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set Temporary Path to generate temporary files +blinkConverterSettings.TempPath = @"C:/HtmlConversion/Temp/"; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; + +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2402,6 +3046,27 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +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 = @"C:/HtmlConversion/BlinkBinaries/"; +//Assign Blink converter settings to HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF document. +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2459,6 +3124,29 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize the blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +//Set the Scale. +blinkConverterSettings.Scale = 1.0f; +//Assign the Blink converter settings to the HTML converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert the URL to a PDF document. +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + +//Save a PDF document +document.Save("Output.pdf"); +//Close the document. +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2487,13 +3175,37 @@ You can download a complete working sample from [GitHub](https://github.com/Sync ## Enable Auto Scaling -The [EnableAutoScaling](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_EnableAutoScaling) property allows you to automatically scale the HTML content to fit the PDF dimensions during the conversion process. When set to true, the HTML content will be resized to fit the size of the generated PDF, ensuring that the content fits within the page without clipping or overflowing. +The [EnableAutoScaling](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_EnableAutoScaling) property allows you to automatically scale the HTML content to fit the PDF dimensions during the conversion process. When set to true, the HTML content will be resized to fit the size of the generated PDF, ensuring that the content fits within the page without clipping or overflowing. + +N> EnableAutoScaling and GetHtmlBounds cannot be used simultaneously in the HTML to PDF conversion process. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +// Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +// Initialize BlinkConverterSettings to configure the Blink rendering engine. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + +// Enables automatic scaling to adjust the HTML content to fit the PDF's dimensions. +blinkConverterSettings.EnableAutoScaling = true; -N> EnableAutoScaling and GetHtmlBounds cannot be used simultaneously in the HTML to PDF conversion process. +// Assigns the Blink settings to the HTML to PDF converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +// Converts the HTML file to a PDF document, using the path of the HTML file. +PdfDocument document = htmlConverter.Convert(Path.GetFullPath("../../../Input.html")); +// Save the generated PDF document to a specified output file. +document.Save("Output.pdf"); +// Close the document. +document.Close(true); -{% tabs %} +{% endhighlight %} -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% highlight c# tabtitle="C# [Windows-specific]" %} using Syncfusion.HtmlConverter; using Syncfusion.Pdf; @@ -2510,7 +3222,7 @@ blinkConverterSettings.EnableAutoScaling = true; htmlConverter.ConverterSettings = blinkConverterSettings; // Converts the HTML file to a PDF document, using the path of the HTML file. PdfDocument document = htmlConverter.Convert(Path.GetFullPath("../../../Input.html")); -// Save the generated PDF document to a specified output file. +// Save the PDF document. document.Save("Output.pdf"); // Close the document. document.Close(true); @@ -2573,6 +3285,28 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize the blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +// Set the conversion timeout to 5000 milliseconds +blinkConverterSettings.ConversionTimeout = 5000; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); + +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2629,6 +3363,30 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +// Initialize HTML to PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +// Initialize Blink converter settings +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +// Set the converter to wait for external fonts to be loaded before converting +blinkConverterSettings.WaitForExternalFonts = true; + +// Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; +// Convert URL (or file path) to PDF +PdfDocument document = htmlConverter.Convert(Path.GetFullPath("Input.html")); + +// Save the PDF document. +document.Save("Output.pdf"); +// Close the document. +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2684,6 +3442,27 @@ document.Close(true); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize the BlinkConverterSettings. +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set true to enable the accessibility tags in PDF generation. +settings.EnableAccessibilityTags= true; +//Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. +htmlConverter.ConverterSettings = settings; +//Convert URL to PDF. +PdfDocument document = htmlConverter.Convert("Input.html"); +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2736,6 +3515,29 @@ File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using System.Drawing.Imaging; +using Syncfusion.HtmlConverter; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize the BlinkConverterSettings. +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set the Image Background color. +settings.ImageBackgroundColor = Color.Transparent; +//Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. +htmlConverter.ConverterSettings = settings; +//Convert HTML to Image. +Image[] image = htmlConverter.ConvertToImage("Input.html"); +for (int i = 0; i < image.Length; i++) +{ + image[i].Save($"Output_{i}.jpg", ImageFormat.Jpeg); +} + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2790,6 +3592,32 @@ File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData); {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using System.Drawing.Imaging; +using Syncfusion.HtmlConverter; + +// Initialize HTML to PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +// Initialize Blink converter settings +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + +// Set the crop region for the HTML conversion based on the bounds of the HTML file +blinkConverterSettings.CropRegion = htmlConverter.GetHtmlBounds(Path.GetFullPath("Input.html")); + +// Assign Blink converter settings to the HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; +// Convert the HTML file to an image +Image[] image = htmlConverter.ConvertToImage(Path.GetFullPath("Input.html")); +//Save the image. +for (int i = 0; i < image.Length; i++) +{ + image[i].Save($"Output_{i}.jpg", ImageFormat.Jpeg); +} + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports Syncfusion.HtmlConverter @@ -2855,6 +3683,37 @@ using (HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter()) {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +// Initialize HTML to PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +{ + // Initialize Blink converter settings + BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + // Set Blink viewport size + blinkConverterSettings.ViewPortSize = new Size(1280, 0); + + // Restricts external CSS and images in local HTML content + blinkConverterSettings.EnableLocalFileAccess = false; + + // Assign Blink converter settings to HTML converter + htmlConverter.ConverterSettings = blinkConverterSettings; + // Read HTML content from file + string html = File.ReadAllText("sample.html"); + // Convert HTML to PDF document + using (PdfDocument document = htmlConverter.Convert(html, "")) + { + // Save the PDF document. + document.Save("Output.pdf"); + } +} + +{% endhighlight %} + {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} Imports System.Drawing @@ -2970,6 +3829,80 @@ public void AddPdfSignatureField(MemoryStream stream) {% endhighlight %} +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using System.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + +// Initialize the HTML to PDF converter using the Blink rendering engine +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +// Configure the converter to preserve form fields in the PDF +BlinkConverterSettings settings = new BlinkConverterSettings +{ + EnableForm = true // Ensures form elements like ,