How does viewport size affects WinForms PDF in Blink rendering engine?
Syncfusion HTML to PDF for .NET is used to convert webpages, SVG, MHTML, and HTML to PDF. Using this library, you can convert HTML to PDF using C# and VB.NET in our Winforms PDF page.
You can adjust the HTML content size in the PDF document using viewport size. Viewport size is internally set to Blink headless browser window size. Based on the provided size, the content will be scaled in the PDF document. Blink rendering engine will automatically calculate the height of the HTML content based on the provided viewport size. The default viewport size is 1024 x 0.
Steps to set viewport size for converting HTML to PDF programmatically:
- Create a new C# Windows Forms application project.
- Install the Syncfusion.HtmlToPdfConverter.Blink.WinForms.nupkg NuGet package as reference to your .NET Framework application from NuGet.org
- Copy the BlinkBinaries from the installed HtmlToPdfConverter package folder and paste it into the folder, which contains the HTMLtoPDF_Sample.csproj file.
- Include the following namespaces in the Form1.cs file.
C#
using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO;
VB.NET
Imports Syncfusion.HtmlConverter Imports Syncfusion.Pdf Imports System.IO
- Use the following code snippet to set viewport size for converting HTML to PDF.
C#
//Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); BlinkConverterSettings blinkSettings = new BlinkConverterSettings(); //Set Blink path blinkSettings.BlinkPath = Path.GetFullPath("../../BlinkBinaries"); //Set viewport size blinkSettings.ViewPortSize = new Size(800, 0); //Assign Blink settings to HTML converter htmlConverter.ConverterSettings = blinkSettings; //Convert HTML to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com"); //Save and close the PDF document document.Save("Sample.pdf"); document.Close(true);
VB.NET
'Initialize HTML to PDF converter Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter(HtmlRenderingEngine.Blink) Dim blinkSettings As BlinkConverterSettings = New BlinkConverterSettings 'Set Blink path blinkSettings.BlinkPath = Path.GetFullPath("../../BlinkBinaries") ‘Set viewport size blinkSettings. ViewPortSize = New Size(800, 0) 'Assign Blink settings to HTML converter htmlConverter.ConverterSettings = blinkSettings ‘Convert HTML to PDF Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") 'Save and close the PDF document document.Save("Sample.pdf") document.Close(True)
A complete working sample can be downloaded from HTMLtoPDF_Sample.zip
By executing the program, you will get the PDF document as follows, screenshots of two different viewport sizes have been attached in this document. You can set any viewport size to Blink rendering engine based on the requirement.
Viewport size - 800 x 0
Viewport size – 1500 x 0
Take a moment to peruse the documentation for Converting HTML to PDF, where you will find other options for URL to PDF, bookmarks, and hyperlinks.
An online sample link for Converting HTML to PDF.
Conclusion
I hope you enjoyed learning about how does viewport size affects WinForms PDF in Blink rendering engine.
You can refer to our Winforms PDF feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!