We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem with conversion from html to pdf

I wanted to test the HTML to PDF conversion following this manual (https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit).

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings settings = new WebKitConverterSettings();
//HTML string and Base URL 
string htmlText = "\"Syncfusion_logo\"

Hello World

"
; string baseUrl = @"C:/Temp/HTMLFiles/"; //Set WebKit path settings.WebKitPath = @"/QtBinaries/"; //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert HTML string to PDF PdfDocument document = htmlConverter.Convert(htmlText, baseUrl); //Save and close the PDF document document.Save("Output.pdf"); document.Close(true);
I follow the instructions, added a reference, set the correct paths, but I still have an error on this line -> 
PdfDocument document = htmlConverter.Convert(htmlText, baseUrl)
I get Syncfusion.Pdf.PdfException error: "Object reference not set to an instance of an object."


What am I doing wrong?


1 Reply 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team February 23, 2021 12:37 PM UTC

Hi Patryk, 
 
Thank you for using Syncfusion products.   
    
We have tried to reproduce the reported exception on our end, but it is working properly. We have created a sample and convert the HTML string to a PDF document, it generates a PDF document without any exception. We were unable to reproduce the exception and we have shared the sample for your reference. Kindly please run the sample on your end and let us know the result.   
   
   
Please refer to the below links for preserving resources (CSS/Images/Scripts etc.,) about HTML string to PDF conversion.        
      
Note: For converting HTML string to PDF, we have to specify the base URL (path of the resources) to load the external images/scripts/styles used in the HTML string. So, please make sure that the provided path (Base URL) contains (styles, scripts, images) used in the HTML string.    
   
If still, you are facing the same exception, kindly provide more details such as a modified sample, product version, environment details (OS, Bit version, RAM, etc) to check the issue on our end. So, that it will be helpful for us to analyze and assist you further on this.   
 
Regards, 
Gowthamraj K 


Marked as answer
Loader.
Up arrow icon