We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to resize the HTML content in PDF during WebKit HTML to PDF conversion

Adjusting HTML content size in PDF is possible by using WebKitViewPort property of WebKit HTML converter.

WebKitViewPort: WebKit viewport size will set to WebKit browser’s window size. If the viewport width is smaller than HTML content width, then WebKit HTML converter use HTML content width as viewport width. WebKit HTML converter automatically calculates the height of HTML based on the viewport width.

Default Viewport size: By default, WebKit HTML converter takes the viewport width of the machine where conversion takes place.

Assemblies Required

  1. Syncfusion.Compression.Base.dll
  2. Syncfusion.HtmlConverter.Base.dll
  3. Syncfusion.Pdf.Base.dll
  4. QtBinaries folder

All the above mentioned assemblies can be get by installing the WebKit installer available in the below link.

WebKit HTML Converter: https://www.syncfusion.com/downloads/latest-version

Code snippet:

// Create a HTML to PDF converter object with default settings

HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);

WebKitConverterSettings webKitSettings = new WebKitConverterSettings();

 

//Set page size

webKitSettings.PdfPageSize = new SizeF(512,692);

 

//Set WebKitpath

webKitSettings.WebKitPath = @"../../../../QtBinaries";

 

//Set WebKit Viewport

//changing height value will not make any difference in output PDF

webKitSettings.WebKitViewPort = new Size(800,0);

           

htmlConverter.ConverterSettings = webKitSettings;

 

//Convert url to pdf

PdfDocument document = htmlConverter.Convert("input.html"); 

   

//Save the document.

document.Save("Sample.pdf");

 

Please refer below screen shots of result with different WebKitViewPort size:

WebKitViewPort

Screenshot

Default System ViewPort Size

Custom ViewPort Size

(800 width)

 

Please refer below Output PDF documents with different WebKitViewPort size,

http://www.syncfusion.com/downloads/support/directtrac/general/ze/Output1439744559  

Working Sample can be downloaded from the below link,

http://www.syncfusion.com/downloads/support/directtrac/general/ze/WebKitViewportSample-153430224

Article ID: Published Date: Last Revised Date: Platform: Control:
7412 02/11/2017 12/18/2017 Windows Forms PDF
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon