How to convert HTML to PDF in Mac and Linux

Hello,

I'm trying to generate a sample pdf from a HTML text with the following code:

public static partial class PdfExtensions
{
public static byte[] ToPdfInvoice(this string text)
{
byte[] pdf = [];

HtmlToPdfConverter htmlConverter = new(HtmlRenderingEngine.Blink);
// BlinkConverterSettings blinkConverterSettings = new();
// blinkConverterSettings.BlinkPath = @"/BlinkBinariesMac/";
// htmlConverter.ConverterSettings = blinkConverterSettings;

string htmlText = "<html><body><p> Hello World</p></body></html>";
string baseUrl = @"";
PdfDocument document = htmlConverter.Convert(htmlText, baseUrl);
FileStream fileStream = new("sample.pdf", FileMode.CreateNew, FileAccess.ReadWrite);
document.Save(fileStream);
document.Close(true);
return pdf;
}
}


I'm getting the error Syncfusion.Pdf.PdfException: Blink files are missing at .../bin/Debug/net8.0/runtimes/osx/native

What am I missing? How to know where are the blink files? I have the following packages installed:

    <PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Linux" Version="23.1.40" />

    <PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Mac" Version="23.1.40" />

    <PackageReference Include="Syncfusion.Licensing" Version="23.1.40" />

    <PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.1.40" />

Do I have to download the HTML Converter Mac from https://www.syncfusion.com/account/downloads/studio/licensed/23_1_36 ? By the way, the HTML Converter for Linux link downloads a zip file with a Windows exe file.

If that is so, what files and how do I have to install them in my project.


Thanks,

Erick




3 Replies

KS Karmegam Seerangan Syncfusion Team October 13, 2023 02:37 PM UTC

Hi Erick,


MAC

The blink binaries exception may occurs due to not unzipping the chromium app. If you want convert html to pdf in MAC machine, you need to manually unzip chromium app. We have also added this details in UG getting started step 8.

Please find the UG documentation,

https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/mac

 

Linux

We have checked the reported issue on our end. This issue may occurs due to missing of required linux dependencies.

Please refer below the getting started UG documentation to installing dependencies in your machine.

https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/linux

 

 

Kindly try the above solution and let us know the result. If you are still facing issue with conversion, Kindly we request you to share the MAC and Linux environment details environment details (OS, bit version, culture settings, RAM size, etc.,)



ER Erick October 21, 2023 01:41 AM UTC

Thank you very much. Unzipping the Chromium app did the trick. I still have to test on Linux.


Erick



SS Swetha Srikumar Syncfusion Team October 23, 2023 09:02 AM UTC

Hi Erick,

Please check and revert back to us, as we will always be happy to assist you.

Regards,

Swetha


Loader.
Up arrow icon