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. Image for the cookie policy date

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

Hi,
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);

            document.Save(@"D:\\SavePDF.pdf");



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

<--html xmlns="http://www.w3.org/1999/xhtml">
<--head>
<--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;} 
<--/style>
<--/head>
<--body>
<--table class="bdc"  border="0" cellpadding="0" cellspacing="0" width="99%">
 <--tbody>
  <--tr>
   <--td align="center">
    <--span>My WebSite of my profile
<--br />
    Website: www.mywebsite.com
<--/td>
  <--/tr>
 <--/tbody>
<--/table>
<--/body>
<--/html>

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!


1 Reply

PV Prakash Viswanathan Syncfusion Team 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;   
//or                
//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. 

Regards, 
Prakash V 


Loader.
Live Chat Icon For mobile
Up arrow icon