HTML to PDF conversion. Content Very small

Im using the Pdf library to convert a html to pdf and show it on a pdfviewer contol. But it shows the content very small. in comparisson on how it should looks i will attached two pdf one that i get from a html online converter and the one that the program did. And a little snippet of the program. 


 PdfDocument documentQuote = htmlConverter.Convert(htmlQuote, baseURL);

 documentQuote.PageSettings.Size = PdfPageSize.A4;

 documentQuote.PageSettings.Orientation = PdfPageOrientation.Portrait;


 BlinkConverterSettings settings = new BlinkConverterSettings();

 settings.EnableForm = true;

 htmlConverter.ConverterSettings = settings;


 string filePath = "CotizacionEjemplo.pdf";


 if (File.Exists(filePath))

 {

     File.Delete(filePath);

     using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))

     {

         //Save and close the PDF document.

         documentQuote.Save(fileStream);

         documentQuote.Close(true);

     }

 }


Attachment: PdfTests_7db95e86.zip

1 Reply 1 reply marked as answer

KS Karmegam Seerangan Syncfusion Team May 20, 2024 12:02 PM UTC

Hi Alexis,



We have checked the reported issue with provided details on our end.  Our HTML converter internally uses the Blink rendering engine. It utilizes a Chrome headless browser for converting HTML to PDF. The PDF document will be saved exactly as it appears in Chromium-based web browsers like Chrome and in print preview. 


We have support to change the viewport size of the output document by using the ViewPortSize or Scale property in the BlinkConverterSettings class.


Additionally, the Blink converter settings should be assigned before executing the Convert method, rather than after the HTML to PDF conversion. Please refer to the attached sample and code snippet for your for guidance.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Minimal_Content_HTMLtoPDF-822001211


Scale:

HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();

//Set scaling factor

blinkConverterSettings.Scale = 1f;

htmlConverter.ConverterSettings = blinkConverterSettings;


ViewPortSize:

HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();

//Set Blink viewport size.

blinkConverterSettings.ViewPortSize = new Size(950, 0);

htmlConverter.ConverterSettings = blinkConverterSettings;


Note: The scaling factor range should be from 0.1 to 2.0, otherwise the conversion fails. Both properties cannot function at the same time. We kindly request you to use any one of them.


Please refer to the below documentation for further information.

Converting HTML to PDF with Scale | Syncfusion

Converting HTML to PDF with View Port Size | Syncfusion


Kindly try the sample and let us know the result. If you are still facing issues, we kindly request you to share the modified sample, package name, package version, and environment details (such as OS platform, bit version, and RAM size) with us to check the reported issue on our end. This information will be more helpful for us to analyze and assist you further on this.


Regards,

Karmegam



Marked as answer
Loader.
Up arrow icon