HTML to PDF conversion with .Net 5 working on windows 10 x64 but not on ubuntu 20.04 x64

I am working with "Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core" package version 19.2.0.55. Using this package I am converting HTML to pdf. The code works fine on windows 10 x64 but doesn't work on Ubuntu 20.04.

On ubuntu when I convert to pdf I get message "Failed to Load PDF", when I open the converted file.

Following is my code:
on Service:

public byte[] GetPdfSyncfusion(List<string> htmlList, string fileName, string className, string mainClass, int layout)

        {

            HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

            WebKitConverterSettings settings = new WebKitConverterSettings();

            PdfDocument document = new PdfDocument();

            Stream[] streamPages = new Stream[htmlList.Count];

            int i = 0;


            //document.PageSettings.Orientation = (layout == 0 ? PdfPageOrientation.Portrait : PdfPageOrientation.Landscape);

            document.PageSettings.Size = PdfPageSize.A4;

            //Set WebKit path

            settings.WebKitPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), isWindows ? "QtBinariesWindows" : "QtBinariesLinux");

            settings.Margin.All = 30;

            //Assign WebKit settings to HTML converter

            htmlConverter.ConverterSettings = settings;


            foreach (string html in htmlList)

            {

                var htmlContent = "<!DOCTYPE html><html lang=\"en\"><head></head><body>{0}</body></html>";

                PdfDocument page = htmlConverter.Convert(string.Format(htmlContent, html), "");

                MemoryStream stream = new MemoryStream();


                //page.PageSettings.Orientation = (layout == 0 ? PdfPageOrientation.Portrait : PdfPageOrientation.Landscape);

                page.PageSettings.Size = PdfPageSize.A4;

                page.Save(stream);

                streamPages[i] = stream;

                i++;

            }


            PdfDocumentBase.Merge(document, streamPages);

            MemoryStream streamDocument = new MemoryStream();


            document.Save(streamDocument);


            return streamDocument.ToArray();

        }

On controller:

public IActionResult GetPDFFromHtmlSyncfusion([FromBody] IEnumerable<string> htmlList, string fileName, string className, string mainClass, int layout)

        {

            string loggedInUser = HttpContext.User.Identity.Name;

            var bytes = _htmlToPdfService.GetPdfSyncfusion(htmlList.ToList(), fileName, className, mainClass, layout);


            return File(bytes, MimeTypes.GetMimeType(fileName), fileName);

        }


3 Replies

GK Gowthamraj Kumar Syncfusion Team September 28, 2021 02:50 PM UTC

Hi Gautam, 

Thank you for contacting Syncfusion support.

We have checked the reported issue with provided details on our end, but it is working properly on our Linux environment. We have attached the sample and output document for your reference. Kindly try the below sample with your input HTML string on your end and let us know the result.   


Please refer the below link for more information, 
If the html string contains any HTTPS files, we need to add OPENSSL assemblies in your machine. We have attached a required OPENSSL (libssl) shared objects, can you please add these files in the QtBinariesLinux folder. Then try the conversion with .net 5.0 and let us know the result. Please find the libssl files from the below link,    
  • Download and extract the file from the above link.
  • Copy the libcrypto.so and libssl.so files to QtBinariesLinux folder.
  • Then try the conversion and check the resultant PDF document.

Please save the Html to PDF document into file and ensure whether it is opened properly or not? Also confirm us whether the issue occurs with Html to PDF converted document or exception occurs while merging with streams?

 
We request you to share the intermediate Html to PDF converted document, exception details, modified sample or videos or screenshot 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 



GD Gautam Dayal September 28, 2021 03:55 PM UTC

I had already followed the below steps:

  1. $ sudo apt-get update
  2. $ sudo apt-get install xvfb
  3. $ sudo apt-get install libssl1.0-dev
  4. $ sudo apt-get install libx11-dev libx11-xcb-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-render0-dev libxcb-shm0-dev libxcb-util0-dev libxcb-xfixes0-dev libxcb-xkb-dev libxcb1-dev libxfixes-dev libxrandr-dev libxrender-dev
But in step 3 I got following error:

Package libssl1.0-dev is not available, but is referred to by another package.

This may mean that the package is missing, has been obsoleted, or

is only available from another source


So I executed the following instead:

$ sudo apt-get install libssl-dev

and it installed

After your reply I added the ssl files to the " QtBinariesLinux " folder and redeployed the project. But still the same error. 


Regards,



GK Gowthamraj Kumar Syncfusion Team September 29, 2021 01:42 PM UTC

Hi Gautam, 

Thank you for your update. 

Kindly provide the read/write/execute permission for Syncfusion.WebKitWrapper file inside the QtBinariesLinux folder on the machine.  Please refer the below KB documentation, 
 

Please confirm whether the provided sample is working or not in your machine? As we request earlier, please confirm us whether the issue occurs with Html to PDF converted document or exception occurs while merging with streams? If the issue occurs in merging, please save the Html to PDF document stream into PDF file and ensure whether it is opened properly or not? 

We request you to share the intermediate Html to PDF converted document, exception details, modified sample or videos or screenshot 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 


Loader.
Up arrow icon