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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Auto scale PDF page height based on HTML data content to cleanly fit on provided page size

Thread ID:





133037 Oct 5,2017 09:34 AM UTC Oct 6,2017 06:34 AM UTC ASP.NET Web Forms 1
Tags: PDF
Asked On October 5, 2017 09:41 AM UTC

I need to fit HTML content on a single pdf page (as using WebKit and HTML conversion of PDF).
But while drawing content goes to next page instead of resize the html content to provide pdf size.

Code snippet:

            float providedHeight = 85;

            float providedWidth = 750;

            System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 0, providedWidth providedHeight );

            //Create page template            

            HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);

            WebKitConverterSettings settings = new WebKitConverterSettings();

            //Set page height of header height

            settings.WebKitPath = HttpContext.Current.Server.MapPath("~/bin/QtBinaries");

            settings.WebKitViewPort = new System.Drawing.Size(750, 0);

            settings.Orientation = PdfPageOrientation.Landscape;

            settings.PdfPageSize = new System.Drawing.SizeF(providedWidth providedHeight );

            settings.SplitImages = false;

            settings.SplitTextLines = false;

            htmlConverter.ConverterSettings = settings;

            string baseUrl = hostedsiteURL;

            PdfDocument document = htmlConverter.Convert(sHTMLDATA, baseUrl);


And provided HTMLDATA as: (please remove "--" from each line)

<--html xmlns="http://www.w3.org/1999/xhtml">
<--style type="text/css">
--.bdc  table td { font-size: 15pt;font-family: Calibri;color: black;} 
--.bdc { font-size: 15pt;font-family: Calibri;color: black;} 
--.bdc  table td select, .bdc  table td input , .bdc  table td textarea {font-size: 15pt;font-family: Calibri;} 
<--table class="bdc"  border="0" cellpadding="0" cellspacing="0" width="99%">
   <--td align="center">
    <--span>My WebSite of my profile
<--br />
    Website: www.mywebsite.com

Please refer attached screen shot of resultant outcome of this link.

Screenshot of outcome (https://ibb.co/gz3y1G)

We are currently using Syncfusion.HtmlConverter HTMLTOPDFCONVERTER with WebKit libraries to convert HTML data to PDF page.

Is there a way in syncfusion to do this?

Thank you!

Prakash Viswanathan [Syncfusion]
Replied On October 6, 2017 06:34 AM UTC

Hi Amit, 

Thanks for contacting Syncfusion support. 

Our WebKit HTML converter already provides support for single PDF page layout. Please refer below code snippet for SinglePageLayout in our WebKit HTML converter,  
//set single page layout with FitWidth   
webKitSettings.SinglePageLayout = SinglePageLayout.FitWidth;   
//set single page layout with FitHeight   
webKitSettings.SinglePageLayout = SinglePageLayout.FitHeight;   

But we have faced issue with single page layout, when we convert a HTML with small page height. We have already updated the details regarding this issue in the incident (which is created by you for HTML header and footer). Please follow the incident for further update regarding this issue. 

Prakash V 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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