Troubleshooting and FAQ

22 Apr 202417 minutes to read

Exception Blink files are missing
Reason The exception may occur if the 'runtimes' folder is not copied correctly from the NuGet folder.
Solution Ensure that the runtimes folder is copied properly to bin folder of the application from NuGet package location.

Please refer to the below screenshot,

Runtime folder

(Or)

You can set the runtimes folder path explicitly in BlinkPath property in BlinkConverterSettings class.

Ex path: C:\HtmlConversion\HTMl-to-PDF\HTMl-to-PDF\bin\Debug\net7.0\runtimes\win-x64\native\

//Initialize the HTML to PDF converter.
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
//Set Blink the binaries path.
blinkConverterSettings.BlinkPath = @"C:/HtmlConversion/BlinkBinaries/";
//Assign the Blink converter settings to HTML converter.
htmlConverter.ConverterSettings = blinkConverterSettings;
//Convert the URL to PDF document.
PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com");
//Create a file stream to save the PDF document. 
FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite);
//Save and close the PDF document.
document.Save(fileStream);
document.Close(true);

BlinkBinaries access is denied in server

Exception BlinkBinaries access is denied in server.
Reason If the BlinkBinaries folder does not have elevated permission for the respective user, then the Blink HTML converter may throw this exception.
Solution You can add read/write/execute permission to for the BlinkBinaries folder for the respective user group.
Exception Blink rendering engine only supported from .NET Framework 4.5.
Reason HTML conversion using blink is only supported from .NET framework 4.5 or above.
Solution The application should target .NET Framework 4.5 or above to convert the HTML using the Blink rendering engine.

Failed to launch chromium: Running as root without –no-sandbox is not supported

Exception Failed to launch chromium: Running as root without --no-sandbox is not supported
Reason The exception may occur in the Linux CentOS/Docker environment due to the Chrome browser unable to launch from sandbox mode in CentOS.
Solution To overcome the exception in the Linux CentOS/Docker environment, provide the execute permission for chrome and chrome-wrapper files inside the BlinkBinaries folder.
Refer to the following screenshot:
Blink chrome file permission
Blink chrome wrapper file permission
Also, please add the following command line arguments in our converter setting.
//Set command line arguments to run without sandbox.
blinkConverterSettings.CommandLineArguments.Add("--no-sandbox");
blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox");

Failed to launch Base

Exception Failed to launch Base
Reason The exception may occur due to missing of required dependent packages.
Solution To overcome the exception, you can ensure the required dependency in docker file.

Failed to launch chromium: Missing required dependent packages

Exception Failed to launch chromium: Missing required dependent packages
Reason The required dependencies for the Chromium are not installed on the system.
Solution Ensure all required dependencies for the Chromium are installed on the system. This may include additional libraries or packages.

Access is denied in runtimes folders. Runtimes folder requires read/write/execute permission

Exception Access is denied in runtimes folders. Runtimes folder requires read/write/execute permission
Reason The exception may occur if the runtimes folder is not accessed.
Solution To overcome the exception, you can add read, write, and execute permissions for the runtimes folder.

Access denied for specified temporary folder

Exception Access denied for specified temporary folder
Reason The specified temporary folder path might be inaccessible.
Solution To overcome the exception, you can add read, write, and execute permissions for the temporary folder. Refer to the following code sample to set the temp folder.

BlinkConverterSettings settings = new BlinkConverterSettings();
settings.TempPath = "D://MyProject//bin";

The temporary folder does not have read permission

Exception The temporary folder does not have read permission
Reason If the temporary folder does not have elevated permission for the respective user, then the Blink HTML converter may throw this exception.
Solution The Blink HTML converter has support for setting the temporary path. Using the TempPath property, you can set any folder path that has read/write/execute permission. Then, the converter uses this path for creating temporary files.
Issue Blink converter may create PDF with blank pages.
Reason When the webpage (HTML) is not available or accessible.
Solution Please check the internet connection and the HTML page is available in the mentioned location.

Check the HTML file or URL is rendered properly in Chrome browser's print preview.

Failed to launch chromium: Due to insufficient permission unable to launch the chromium process for conversion

Exception Failed to launch chromium: Due to insufficient permission unable to launch chromium process for conversion.
Reason This exception might arise because the Blink binary files lack sufficient permissions to be launched from the specified BlinkPath location.
Solution To overcome this exception, you can provide an execute permission for chrome and chrome-wrapper files inside the runtimes/linux/native folder by using the docker command.

ExcludeAssets

COPY . /app
WORKDIR /app

RUN chmod +x /app/runtimes/linux/native/chrome && \
    chmod +x /app/runtimes/linux/native/chrome-wrapper

Images or other contents in the HTML are missing in the resultant PDF document

Issue Images or other contents in the HTML are missing in the resultant PDF document.
Reason The issue may be due to the slow internet connection or due to the behavior that the conversion completed before the page is loaded completely.
Solution To overcome this issue, add suitable delay for the conversion using the AdditionalDelay property of the HTMLConverter.

BlinkConverterSettings settings = new BlinkConverterSettings();
settings.AdditionalDelay = 4000;
Reason While converting HTML string to PDF, the resources may be missed due to the invalid Base URL.
Solution Overcome this issue by passing the valid base URL (path of the resources) along with the HTML string.
Issue Blink conversion failed in Azure app service (Windows). “The process was terminated due to an unhandled exception”
Reason Blink rendering engine uses GDI calls for viewing and rendering the webpages. But Azure app service blocks GDI calls in Azure website environment. As azure website does not have the elevated permission and enough rights, so we could not launch the Chrome headless browser in Azure app service (Azure website and Azure function).
Solution You can convert HTML to PDF using the Blink rendering engine in Azure cloud service (which has the elevated permission and rights to access the GDI calls). Refer to this link for more information.
Issue Unable to convert unsecured https URL to PDF using Blink.
Reason The issue is happen due to invalid SSL certificate errors in unsecured sites.
Solution You can able to bypass the invalid SSL certificate errors using the command line arguments property of Blink converter settings.

BlinkConverterSettings settings = new BlinkConverterSettings();
settings.CommandLineArguments.Add("--ignore-certificate-errors");

Conversion failure in windows server 2012 R2

Issue Conversion failure in windows server 2012 R2.
Reason The issue may happen due to windows server environment permission restriction.
Solution We can resolve this permission related failure in the Blink rendering engine using below command line arguments in our converter settings.

//Set command line arguments to run without sandbox.
blinkConverterSettings.CommandLineArguments.Add("--no-sandbox");
blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox");

Converting the HTML to PDF fails in x32 bit windows system environment

Exception Converting the HTML to PDF fails in x32 bit windows system environment.
Reason The existing x64 bit Blink binaries windows are not compatible with x32 bit windows system architecture.
Solution To overcome this issue, we can use the x32 bit blink binaries. The x32 bit windows blink binaries are compatible with the x32 bit windows system environment. Please download the x32 bit blink binaries for windows here and replace these binaries in the existing x64 bit blink binaries folder.

ERROR:The specified module could not be found in windows server 2012 R2

Exception The specified module could not be found in windows server 2012 R2.
Reason The issue happened because the Windows Server Essentials Media Pack was missing in the Windows server 2012 R2.
Solution We can resolve this issue by installing the Windows Server Essentials Media Pack. To install the Windows Server Essentials Media Pack, first install the Windows Server Essentials.
1. Open the Server Manager in the Taskbar.
2. Click Manage in the Server Manager and select Add Roles and Features option.
3. Select the Role-based or feature-based installation option and click next.
4. In the left side menu, select server roles, then Windows Server Essentials Experience in the server roles and then click next.
5. Now, the Windows Server Essentials will be installed.
6. After successful installation, install the Windows Server Essentials Media Pack.
Go to the official website to download and Install the Windows Server Essentials Media Pack.

Note:

This version is only applicable to Windows Server 2012 R2 Standard.

How to Exclude BlinkBinaries or Runtime Files in Build or Deployment

The runtime files, or blink binaries, will be copied into a bin or published folder while building and publishing the application.

By including the native option in the package reference of the csproj file, you can exclude the runtime files or blink binaries from being copied into the bin or publish folder while building and publishing the application. But you need to place the BlinkBinaries in the server disk and set the BlinkPath in the BlinkConverterSettings to perform the conversion.

Note:

Using this approach, you can reduce the deployment size on your own servers.

Refer to the following package reference:

ExcludeAssets

HTML conversion support in Azure

HTML conversion support in Azure
Azure App Service (Linux) Yes
Azure Functions (Linux) Yes
Azure Cloud Service Yes
Azure App Service with Linux docker Yes

Failed to convert Webpage exception with Linux docker in Mac M1 machine.

Exception Failed to convert Webpage exception using Linux Docker in Mac M1 system environment.
Reason The existing x64-bit Blink binaries for Linux are not compatible with the x64 ARM Mac M1 system architecture with Linux Docker.
Solution To resolve this issue, we can install the chromium using the docker file and set the Blink Path to the location where chromium is installed.

Docker File:

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base 

	RUN apt-get update && apt-get install -y \ 

    libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \ 

    libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \ 

    libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \ 

    libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \ 

    libnss3 libgbm1 chromium 

	WORKDIR /app 

	EXPOSE 80 

	EXPOSE 443
Code snippet:
BlinkConverterSettings settings = new BlinkConverterSettings();  

	//To utilize the Blink binaries from the arm64-based chromium installed using the docker file, execute the following command.   

	settings.BlinkPath = @"/usr/lib/chromium/chromium";
Exception Background color missing issue in HTML Header and Footer.
Reason We do not have the support for adding a custom CSS style in the HTML header and footer.
Solution To resolve this issue, we can add inline styles in element. However, we have attached the sample and output documents for your reference.

HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
	//Initialize blink converter settings. 
	BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
	//Set the Blink viewport size.
	blinkConverterSettings.ViewPortSize = new Size(1280, 0);
	//Set the html margin-top value based on the html header height and margin-top value.
	blinkConverterSettings.Margin.Top = 70;
	//Set the html margin-bottom value based on the html footer height and margin-bottom value.
	blinkConverterSettings.Margin.Bottom = 40;
	//Set the custom HTML header to add at the top of each page.
	blinkConverterSettings.HtmlHeader = " <div style=\"background-color: blue; -webkit-print-color-adjust: exact; margin-left: 40px; font-size: 10px;\">HTML Header</div>";
	//Set the custom HTML footer to add at the bottom of each page.
	blinkConverterSettings.HtmlFooter = " <div style=\"background-color: blue; -webkit-print-color-adjust: exact;margin-left: 40px; font-size: 10px;\">HTML Footer</div>";
	//Assign Blink converter settings to the HTML converter.
	htmlConverter.ConverterSettings = blinkConverterSettings;
	//Convert the URL to a PDF document.
	PdfDocument document = htmlConverter.Convert("<div>Hello World</div>",string.Empty);
	//Create a filestream.
	FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite);
	//Save and close a PDF document.
	document.Save(fileStream);
	document.Close(true);
You can downloaded a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/HTML-Footer-Background-Colour/.NET).

Zombie process are not closed by default from chrome headless in Linux platform

The zombie process are not closed by default from chrome headless in Linux. However, We can resolve the zombie process issue by using the below command line arguments in converter settings.

//Set command line arguments to run without the sandbox.

		settings.CommandLineArguments.Add("--no-sandbox");

		settings.CommandLineArguments.Add("--disable-setuid-sandbox");

		settings.CommandLineArguments.Add("--no-zygote");

		settings.CommandLineArguments.Add("--disable-dev-shm-usage");

		settings.CommandLineArguments.Add("--single-process");

Failed to launch chromium: Missing required dependent packages issue occurs in Azure function Linux with premium plans.

Exception Failed to launch chromium: Missing required dependent packages issue occurs in Azure function Linux with premium plans.
Reason The reported issue occurs due to missing of required Linux dependencies in Azure function to perform the conversion in premium plans (such as Ep1)
Solution To overcome this issue by installing the Linux dependencies package in SSH window. Please refer the below commands and screenshot,
apt-get update && apt-get install -yq --no-install-recommends libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 libnss3 libgbm1


Please refer to the below screenshot,




(Or)

We can install the required dependencies using the dependencies vis shell script. Please find the below.




code snippet:

private static void InstallLinuxPackages(FileInfo functionAppDirectory)
	{
		if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
		{
			return;
		}
		FileAccessPermissions ExecutableFilePermissions = FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite | FileAccessPermissions.UserExecute |
		FileAccessPermissions.GroupRead | FileAccessPermissions.GroupExecute | FileAccessPermissions.OtherRead | FileAccessPermissions.OtherExecute;
		//Install the dependencies packages for HTML to PDF conversion in Linux
		string shellFilePath = Path.Combine(functionAppDirectory.Directory.Parent.FullName, @"wwwroot/data");
		string tempBlinkDir = Path.GetTempPath();
		string dependenciesPath = Path.Combine(tempBlinkDir, "dependenciesInstall.sh");
		if (!File.Exists(dependenciesPath))
		{
			CopyFilesRecursively(shellFilePath, tempBlinkDir);
			var execPath = Path.Combine(tempBlinkDir, "dependenciesInstall.sh");
			if (File.Exists(execPath))
			{
				var code = Function1.Chmod(execPath, ExecutableFilePermissions);
				if (code != 0)
				{
					throw new Exception("Chmod operation failed");
				}
			}
			Process process = new Process
			{
				StartInfo = new ProcessStartInfo
				{
					FileName = "/bin/bash",
					Arguments = "-c " + execPath,
					CreateNoWindow = true,
					UseShellExecute = false,
				}
			};
			process.Start();
			process.WaitForExit();
		}
	}

Failed to load Chrome DLL exception occurs on Windows 7/8 and Windows Server 2008/2012 machines

Exception Failed to load Chrome DLL exception occurs on Windows 7/8 and Windows Server 2008/2012 machines.
Reason The reported issue occurs due to an unsupported OS platform with the latest binaries.
Solution If you are using Windows 7/8 or Windows Server 2008/2012, please use Chromium version 109 instead of the newer versions. Chromium has discontinued support for these operating systems, and the last compatible version is 109.

Please refer to the below thread for more information, https://support.google.com/chrome/thread/185534985
Blink binaries (Version 109.0.5414.75), https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlinkBinaries_109.0.5414.7560606898

There was an error opening this document. This file is already open or in use by another application.

Issue There was an error opening this document. This file is already open or in use by another application.
Reason The reported issue occurs due to the document or file not being properly disposed or closed, leading to conflicts when attempting to access it again.
Solution We can resolve the reported issue by using the FileStream within the "using" block.
using (FileStream fs = new FileStream("path_to_file", FileMode.Open))
	{
    	// Use the file here
	} // File stream is automatically closed and disposed
Or Dispose of the FileStream at the end of the process and ensure that the file or document is not already open in another application.
PdfDocument document = htmlConverter.Convert(");

	FileStream fileStream = new FileStream(baseUrl+ "Bill_PDF_04_16_24.pdf", FileMode.CreateNew, FileAccess.ReadWrite);

	//Save and close the PDF document.

	document.Save(fileStream);

	document.Close(true);

	document.Dispose();

	fileStream.Dispose();