This project has moved and is read-only. For the latest updates, please go here.

HTML Content Size in PDF

Sep 21, 2016 at 8:59 AM
I am using your HTML to PDF tool in my ASP.NET application to create some PDF reports from the HTML reports generated by my application and so far I am really impressed with how easy is to do this with your tool and how accurate the results can be.

Now I have a small issue and I would need your help. It seems the the text and images are smaller in PDF than they are in the HTML page. It looks like the whole HTML content was resized in PDF page. My code is very simple and it was copied from your example:
    HtmlToPdf htmlToPdfConverter = new HtmlToPdf(); 
    htmlToPdfConverter.HtmlLoadedTimeout = 60; 
    htmlToPdfConverter.Document.PageSize = PdfPageSiz.A4; 
    htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Portrait; 
    htmlToPdfConverter.Document.Margins = new PdfMargins(0); 

    byte[] pdfBuffer = null;
    string htmlCode = GetReportHtml(); 
    string baseUrl = GetReportUrl(); 

    pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlCode, baseUrl);    
    HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf"); 
        String.Format("{0}; filename=Report.pdf; size={1}", "attachment",         
Could you help? I want to have the HTML report at real size in PDF.
Sep 21, 2016 at 9:09 AM
The HTML width is given by the BrowserWidth property of the HiQPdf.HtmlToPdf class which is 1200 pixels by default. At a default DPI of 96 the HTML width is 12.5 inch which is larger than the default A4 portrait page width of 8.27 inch and the HTML is scaled down to fit the PDF page which means that the text and images might appear smaller than they are in HTML.

There are two options to avoid scaling down the HTML rendered in PDF:
  1. To set to false the FitPageWidth property of the HiQPdf.PdfDocumentControl class
An object of the HiQPdf.PdfDocumentControl type is exposed by the Document property of the HiQPdf.HtmlToPdf class. In this case the PDF page size width will be automatically resized to display the whole HTML. You can disable this behavior if you set the ResizePageWidth property of the HiQPdf.PdfDocumentControl class to false.
  1. To set the BrowserWidth property of the HiQPdf.HtmlToPdf class to a smaller value
For a A4 portrait PDF page without margins the BrowserWidth property should be set to 793 pixels which is the result of multiplying the width of the PDF page 8.27 inch with 96 DPI. If you have set the left or the right margin for the PDF pages you should take this in consideration when calculating the browser width.
Marked as answer by hiqpdf on 9/21/2016 at 1:10 AM