Articles in this section
Category / Section

How to Perform HTML to PDF Conversion with the Latest Chromium Binaries using C#

1 min read

Our Syncfusion® HTML-to-PDF converter is a .NET PDF library that allows for the conversion of webpages, SVG, MHTML, and HTML files to PDF using C#. It utilizes the popular Blink rendering engine (Google Chrome) and is known for its reliability and accuracy. The output preserves all graphics, images, text, fonts, and layout of the original HTML document or webpage.

To ensure smooth conversion, the Syncfusion NuGet package responsible for HTML to PDF conversion automatically manages and utilizes the Chromium binaries at runtime. This article explains how to download the latest Chromium binaries and integrate them into the conversion process.

Steps to perform HTML to PDF conversion with the latest chromium binaries

Step 1: Download the Latest Chromium Binaries
Woolyss Chromium Builds
Chromium Browser Snapshots

Step 2: Utilize the Downloaded Latest Chromium Binaries in Conversion
There are two approaches to using the latest Chromium binaries for HTML to PDF conversion.

Approach 1: Use the Installed Chromium Binaries
If you already have Chromium installed on your system, you can use its binaries. The latest Chromium binaries are typically located in the following directory:

C:\Program Files\Google\Chrome\Application

From this location, copy the chrome.exe file and paste it into the folder corresponding to the installed version (for example, 132.0.6834.112).

InstallVersion.png

Once you’ve done this, specify the path to the folder where chrome.exe is located by setting the BlinkPath property in the BlinkConverterSettings. Here’s an example:

C:\Program Files\Google\Chrome\Application\132.0.6834.112

Conversion code Example:
C#

// Instantiate a new HtmlToPdfConverter object which will handle the HTML to PDF conversion.
HtmlToPdfConverter pdfConverter = new HtmlToPdfConverter();
// Define the settings for the Blink PDF converter (part of the conversion engine).
BlinkConverterSettings converterSettings = new BlinkConverterSettings
{
  // Set the orientation of the PDF pages to Portrait.
  Orientation = PdfPageOrientation.Portrait,
  // The line below is commented out but could enable automatic scaling of the document. 
  // EnableAutoScaling = true, 
  // Set the page size to A4, which is commonly used for documents.
  PdfPageSize = PdfPageSize.A4,
  // Set the scale of the output PDF to 1.0 (default size without scaling).
  Scale = 1.0f,
};

// Check if the current operating system is Linux.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
   // Add command-line arguments to disable sandboxing when running on Linux.
   // This is often necessary for proper execution of Blink-based conversion in Linux environments.
   converterSettings.CommandLineArguments.Add("--no-sandbox");
   converterSettings.CommandLineArguments.Add("--disable-setuid-sandbox");
}
// Specify the path to the Blink executable, which is used for rendering HTML to PDF.
converterSettings.BlinkPath = @"C:\Program Files\Google\Chrome\Application\132.0.6834.112\";
// Assign the settings to the HtmlToPdfConverter object.
pdfConverter.ConverterSettings = converterSettings;
// Define the base URL for resolving any relative URLs in the HTML file.
const string baseUrl = @"https://qa-living-apac-agorainsights.devtest.mrisoftware.com";
// Read the contents of the HTML file into a string variable.
string htmlContent = File.ReadAllText("sample.html");
// Convert the HTML file to a PDF document, using the specified base URL for external resources.
PdfDocument pdfDocument = pdfConverter.Convert(htmlContent, baseUrl);

// Use a 'using' statement to automatically close the file stream when done.
using (FileStream pdfFileStream = new FileStream("HTML-to-PDF.pdf", FileMode.Create, FileAccess.ReadWrite))
{
   // Save the generated PDF document to the specified file stream.
   pdfDocument.Save(pdfFileStream);
}
// Close the PDF document.
pdfDocument.Close(true);

Approach 2: Use Downloaded Chromium Binaries

If you prefer to download the Chromium binaries instead of using the installed ones, you can download them from the links provided above.

Once downloaded, follow the same steps as mentioned in Approach 1 to set the BlinkPath property in the BlinkConverterSettings to the path of the downloaded Chromium binaries.

Conclusion

In this article, you learned how to perform HTML to PDF conversion using the latest Chromium binaries in C#. Whether you’re using system-installed or downloaded Chromium binaries, the integration is seamless with Syncfusion’s HTML-to-PDF converter.

For more information on features, code examples, and troubleshooting, refer to the HTML to PDF Features and HTML to PDF Troubleshooting sections. These resources provide detailed guidance and solutions for common issues during HTML to PDF conversion.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied