HtmlToPdfConverter getting blank PDF.

I have referred below link for doing a html to pdf conversion

https://www.syncfusion.com/kb/8483/how-to-convert-html-to-pdf-in-asp-net-core-windows

I have used .net core 3.1 and Qbinaries version 19, but getting blank PDF.  Front end angular is used.

code is like this.

[HttpGet("ExportToPDF")]

public IActionResult ExportToPDF()

{

//Initialize HTML to PDF converter

HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

WebKitConverterSettings settings = new WebKitConverterSettings();

//Set WebKit path

settings.WebKitPath = Path.Combine(hostingEnvironment.ContentRootPath, "QtBinariesWindows");

//Assign WebKit settings to HTML converter

htmlConverter.ConverterSettings = settings;

//Convert URL to PDF

PdfDocument document = htmlConverter.Convert("https://www.google.com");

MemoryStream stream = new MemoryStream();

document.Save(stream);

document.Close(true);

return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Output.pdf");

}


EDIT:-

After installing open ssl libraries, now getting PDF for " https://www.google.com", but when i am giving some local URL(http://localhost:4200/#/simetry/visualizations/dashboards/1) getting blank PDF.

tried adding, used for authorization

settings.HttpRequestHeaders.Add("Authorization", "Bearer ");

even token too.

settings.Cookies.Add("TOKEN", "");


Even it is not exporting the landing page.



Request you to suggest.


1 Reply

GK Gowthamraj Kumar Syncfusion Team July 28, 2021 12:37 PM UTC

Hi Manoj,

Thank you for contacting Syncfusion support.  
 
Our HTML to PDF conversion supports, windows, form and token based authentication. Kindly refer below links for more information about converting authenticated web page to PDF.  


We can convert the authenticated web page to PDF using cookies in HTML to PDF converter, please refer below links for more information. Kindly try the conversion with cookies in our HTML to PDF converter to avoid the empty page issue.   
 
Still you are getting blank page, kindly try the additional delay to the converter for loading the external resources (styles, scripts, images etc.,). Please refer below code snippet to set the additional delay, 

//Set additional delay; units in milliseconds 
Settings.AdditionalDelay = 4000; 
 
Please refer the below links for more information about Additional delay, 

We can get the HTML string of view page, please refer below link for more information, You also can get the HTML string using javascript on a button click and then this to the server side for converting HTML to PDF.  
 
Please try the above suggestions and if still the same issue occurs, kindly provide more details such as simple sample, issue screenshot, output document to reproduced the issue in our end. So, that it will be helpful for us to analyze and assist you further on this. 

Regards,
 
Gowthamraj K 


Loader.
Up arrow icon