Conversion from HTML to PDF is slow

I'm trying to convert an HTML file which has some tables and no JavaScript using the code below, the conversion time is too much compared with when converting an Excel file to PDF.

​HtmlToPdfConverter pdfConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);

WebKitConverterSettings sett = new WebKitConverterSettings();

sett.WebKitPath = @"../../QtBinaries/";

sett.PdfPageSize = PdfPageSize.A4;

sett.Margin.All = 15;

sett.SinglePageLayout = Syncfusion.Pdf.HtmlToPdf.SinglePageLayout.FitHeight;

sett.WebKitViewPort = new Size(720,0);

pdfConverter.ConverterSettings = sett;               

PdfDocument pdf = pdfConverter.Convert(@"cb.html");

pdf.Save($@"res.pdf");

Can there be optimizations for the performance to improve?


9 Replies

GK Gowthamraj Kumar Syncfusion Team September 28, 2021 09:06 AM UTC

Hi Olayinka, 

Thank you for your contacting Syncfusion support. 

WebKit HTML converter internally make use of QtWebKit rendering engine for converting HTML to PDF, which uses QApplication for the conversion. We internally creates and launches a surrogate process from a temporary folder to do the conversion. It will load the browser and start to load the html file, once loading is completed it will be moved to conversion process. Once the conversion is completed in webkit rendering engine, we will load and apply the customizations as per the provided converter settings. So that it will take some amount of reasonable time to process the Html to PDF conversion. 


Please let us know if you need any further assistance with this. 

Regards, 
Gowthamraj K 



OL Olayinka replied to Gowthamraj Kumar September 28, 2021 12:04 PM UTC

I have several autogenerated HTML files to convert to PDF, is there a way to make the process faster, possibly by loading the browser and the conversion process once until all the HTML files are converted?



GK Gowthamraj Kumar Syncfusion Team September 29, 2021 02:13 PM UTC

Hi Olayinka, 

Thank you for your update. 

No. It is not possible to achieve your requirement with our Html to PDF converter. As we said earlier, we internally creates and launches a surrogate process from a temporary folder to do the conversion. It will load the browser and start to load the html file, once loading is completed it will be moved to conversion process. Once the conversion is completed in webkit rendering engine, we will load and apply the customizations as per the provided converter settings. So that it will take some amount of reasonable time to process the Html to PDF conversion. 

Regards, 
Gowthamraj K 



OL Olayinka October 3, 2021 06:34 PM UTC

Ok. Please, how do I fit the webpage to a single page, such that if the height is greater than A4, it should be fit to a page?



GK Gowthamraj Kumar Syncfusion Team October 4, 2021 11:55 AM UTC

Hi Olayinka, 
 
Thank you for your update.

 
Our Html to PDF converter provide support for converting the whole HTML content into a single PDF page by using SinglePageLayout property. The PDF page size is limited to 14400 points. There are two options to enable this feature, since this is disabled by default.  
 
Fit width option: Using this option HTML converter adjust the PDF page height based on the HTML content height. PDF page width remains constant for this option. 
Fit height option: Using this option HTML converter scale the HTML content and PDF page width to render the whole HTML content within the height. PDF page height remains constant for this option. 
 
As we said, the PDF page size is limited to 14400 points (200 inches) for a single page, so that the HTML contents are rendered on half of the first page itself and the remaining parts are displayed as white spaces. This is our default behavior of single-page layout implementation.     
  
Please refer to the below links for more information,    
 
Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 



SC sb captures March 4, 2022 01:09 AM UTC

Few autogenerated HTML records to change over to PDF, is there a method for making the interaction quicker, potentially by stacking the program and the transformation cycle once until all the HTML documents are changed over?



PV Prakash Viswanathan Syncfusion Team March 4, 2022 06:02 PM UTC

Hi sb captures,


Our HTML to PDF converter library internally using QtWebKit and Blink rendering engine for converting HTML to PDF. We already have best performance for converting HTML to PDF. As we said earlier in this thread, all the conversion will be performed in unique internal process.


If you are facing any issues in HTML to PDF conversion, kindly share us the complete code snippet, product version, input HTML file or URL. It will be helpful for us to analyse and assist you further on this.


Regards,

Prakash V



SC sb captures March 5, 2022 01:35 AM UTC

Hey Parkash, Thanks for your response; however, this issue I'm facing is not with mypcfile it might be something else!



GK Gowthamraj Kumar Syncfusion Team March 7, 2022 11:46 AM UTC

Hi sb captures, 
 
As we requested earlier, could you please share us the complete code snippet, product version, input HTML file or URL (with all resource such as image, scripts, styles etc), performance details. It will be helpful for us to analyse and assist you further on this. 
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon