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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

133037 Oct 5,2017 05:34 AM Oct 6,2017 02:34 AM ASP.NET Web Forms 1
loading
Tags: PDF
Amit
Asked On October 5, 2017 05:41 AM

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!


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

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 


CONFIRMATION

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.

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.

;