HtmlToPdfConverter error when using .NET Core background service installed as windows service

When using HtmlToPdfConverter in a .NET Core background service installed as windows service the intialisation of the HtmlToPdfConverter creates the error


Invalid URI: The URI is empty.




This is snippet from Event Viewer




CoreCLR Version: 8.0.824.36612


.NET Version: 8.0.8


Description: The process was terminated due to an unhandled exception.


Exception Info: System.UriFormatException: Invalid URI: The URI is empty.


   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)


   at System.Uri..ctor(String uriString)


   at Syncfusion.HtmlConverter.BlinkConverterSettings..ctor()


   at Syncfusion.HtmlConverter.HtmlToPdfConverter.set_RenderingEngine(HtmlRenderingEngine value)




We have used the Nuget package Syncfusion.HtmlToPdfConverter.Net.Windows v27.1.58


Do we need to specifically reference a certain URI when using the HtmlToPdfConverter in this way?


9 Replies

AM Arumugam Muppidathi Syncfusion Team November 7, 2024 02:08 PM UTC

Hi Martin,


Thank you for reaching out to us.


Our Syncfusion HTML to PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML files to PDF using C#. It uses popular rendering engines such as Blink (Google Chrome) and is reliable and accurate. The result preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage.  Please find our documentation to perform HTML to PDF conversion using blink rendering engine.

 

Converting HTML to PDF | Syncfusion

 

However, we have attached the sample and output document below for your reference

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/HTML-to-PDF-NET8.0-1603290155
Output: https://www.syncfusion.com/downloads/support/directtrac/general/pd/HTML-to-PDF-1204513699

Since the provided details are not enough to replicate the issue.  We kindly request you to share the complete code snippet, input HTML document or specific URL, modified sample, .NET version and environment details to replicate the same issue on our end. This information will be more helpful for us to analyze and provide you with a prompt solution.


Regards,
Arumugam M



MA Martin November 7, 2024 10:02 PM UTC

I have attached the Program and Worker.cs files. If I debug it works fine and converts html to PDF. However when installed as a windows service using sc create the HtmlToPdfConverter has an error.


Attachment: HD_Bundle_File_Watcher_acd355eb.zip


AM Arumugam Muppidathi Syncfusion Team November 8, 2024 03:39 PM UTC

Hi Martin,


Thank you for providing the details. Currently, we are trying to reproduce the reported issue with the provided details, and we will provide further details on November 12, 2024


Regards,
Arumugam M



AM Arumugam Muppidathi Syncfusion Team November 12, 2024 04:35 PM UTC

Hi Martin,


Currently, we are facing issue in reproducing the reported issue with the provided details.  We are checking on this with high priority and we will update further details on November 14, 2024.  Meanwhile, we kindly request you to share the steps to reproduce the reported issue.  This will be more helpful for us to reproduce the issue and provide a prompt solution.


Regards,
Arumugam M



MH Martin Holmes November 13, 2024 03:31 PM UTC

Hi there, i have created a sample project and upload to github: https://github.com/martingholmes/Test-HTML-to-PDF


When publish i use the following setting:

Screenshot 2024-11-13 152403.png


Then it is installed as a windows service using sc create "servicename" binpath= "path to exe"


When an email is added to the watched folder and the HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); is called it errors with error message  Invalid URI: The URI is empty.


Thanks, Martin



AM Arumugam Muppidathi Syncfusion Team November 14, 2024 04:42 PM UTC

Hi Martin,


Upon further analysis, we suspect that the reported issue may occur with your specific input documents.  We kindly request you to share your input documents with us.  This will be more helpful for us to analyze and provide a prompt solution.


Regards,
Arumugam M



MH Martin Holmes November 15, 2024 08:58 PM UTC

Hi Arumugam,


It is definetely not the input document as the code does not get that far. The line that errors is: 

HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();


The relevant document is not passed to this line of code. 


Thanks, Martin



MH Martin Holmes November 15, 2024 11:53 PM UTC

You can close this ticket, I have resolved the issue. The issue was selecting "Produce single file" on publish. Untick this and it works fine.


Screenshot 2024-11-15 235045.png

Thanks, Martin



AM Arumugam Muppidathi Syncfusion Team November 18, 2024 07:30 AM UTC

Hi Martin,


We are glad to hear that you resolved the issue. Please get back to us if you need further assistance.


Regards,

Arumugam M


Loader.
Up arrow icon