WebKitConverter from Url greater width than the pdf document

Hello,

I've been using the WebKitConverter for converting an Html page with some charts into a PdfDocument, in this case I'm creating a PDF document and inside the last page I'm drawing the converted Html page.
I managed to make it work but I stumbled into a very strange behaviour:
  • when debugging the code on my local machine it works perfectly
  • when debugging the code on our Server it works perfectly
  • after the deploy on IIS on our Server the Html template, when drawn inside the pdf, has a width larger than the pdf with some content going over the margins
All the debug is done using Visual Studio 2019,  QtBinaries are imported correctly and the dll files for OPENSSL are there too.
In those first two cases my html contains a table and two charts that are shown correctly inside the margins of my pdf page, in the third case the html is the same as before but when converted the table and the charts are much higher and the width is greater than the available, resulting in some content cut from the borders.
Is there any settings inside IIS that may cause this behaviour?

This is the code I've been using:
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings converterSettings = new WebKitConverterSettings();

converterSettings.WebKitPath = $"{dir}\\QtBinaries";
converterSettings.AdditionalDelay = 2000;

htmlConverter.ConverterSettings = converterSettings;

PdfDocument docWeb = htmlConverter.Convert("myurl");
using (MemoryStream stream = new MemoryStream())
{
docWeb.Save(stream);

PdfLoadedDocument htmlDocument = new PdfLoadedDocument(stream);
PdfTemplate htmlTemplate = htmlDocument.Pages[0].CreateTemplate();

graphics.DrawPdfTemplate(htmlTemplate, new PointF(-20, layoutResult.Bounds.Bottom + 20));
}

The delay is used for waiting the charts to be initialized completely. I tried to add these following options but the result didn't change:
converterSettings.AspectRatio = AspectRatio.FitPageSize;
converterSettings.EnableJavaScript = true;
converterSettings.SinglePageLayout = Syncfusion.Pdf.HtmlToPdf.SinglePageLayout.FitWidth;
converterSettings.PdfPageSize = new SizeF(page.Size.Width, page.Size.Height);

In the attachment you can find a screenshot of the problem (left window is debug in localhost, right window is the one from IIS)

Regards,
     Daniele

Attachment: Syncfusion_pdf_error_72851c79.zip

3 Replies 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team October 22, 2020 01:34 PM UTC

Hi DANILO, 

Thank you for using Syncfusion products. 

We have tried to reproduce the reported issue, but it is working properly. We have checked the conversion with simple charts in WebKit converter. We suspect that the reported issue may occurs due to viewport size adjustment. By default, WebKit rendering engine using system viewport size for the conversion. The system viewport size may differs based on the machine/application. So, kindly try the conversion with some fixed viewport size and let us know the result. Please refer below code snippet for setting viewport size, 

//Set WebKit viewport size 
webKitSettings.WebKitViewPort = new Size(1500, 0); 

Kindly refer to the below links for more information about Viewport size, 
 
Note: The default viewport size is 1024 x 0.  
 
If still you are facing the same issue, kindly provide more details such as complete input HTML file/URL (with all resources styles, scripts, etc.,), product version and environment details (OS, bit version, culture settings, RAM size etc.,) to reproduce the issue in our end. So, that it will be helpful for us to analyze and assist you further on this. 

Regards, 
Gowthamraj K 


Marked as answer

DL DANILO LONGONI October 26, 2020 12:22 PM UTC

Dear Gowthamraj,

thank you for your support.
That definitely was the problem, your solution helped me solving it by putting 1920*1080 as my viewport for converting correctly my html.


Thank you so much!
     Daniele





GK Gowthamraj Kumar Syncfusion Team October 27, 2020 06:47 AM UTC

Hi DANILO, 

Thank you for your update. We are glad to know that your problem has been solved. 

Regards, 
Gowthamraj K 


Loader.
Up arrow icon