Click or drag to resize
Pdf Library for .NET

Troubleshooting

Read the following sections to learn how to fix common problems that might appear when using SelectPdf library for .NET:

Conversion failure. The rendering engine could not be found.

The HTML-to-PDF conversion needs the native Chromium (CEF) engine folder (Chromium-CEF-154.0.28) next to the application. It is supplied by the SelectPdf.Universal.Native.<rid> package and is copied to the output folder at build time. If it is missing at run time, confirm the correct Native package (matching your deployment runtime identifier) is installed and published. The engine folder path can also be set explicitly with ChromiumEnginePath. More details in the deployment section.

Conversion failure. Exception of type 'System.OutOfMemoryException' was thrown.

This error might occur in case of html to pdf conversion of large web pages, containing many / very large images.

Our tool initially converts the images to bitmaps and then compresses them to jpg internally. If you have several large images (with large resolutions), even if you display them in a 20x30 box in html, they are still large and when converted to bmp, they consume a lot of memory.

To work around this problem, you need to have your images optimized for the web. Alternatively, run the application as a 64-bit process, which allows the allocation of a lot more memory than a 32-bit process.

Conversion failure error 5.

The error code is this:

ERROR_ACCESS_DENIED

5 (0x5)

Access is denied.

The engine binary needs execute permission. On Linux the library restores the execute bit automatically before launching the engine, but if the application directory is mounted noexec, or on a host that blocks launching the engine, grant execute permission to the CEF executable inside the Chromium-CEF-154.0.28 folder.

Conversion failure error 32.

The error code is this:

ERROR_SHARING_VIOLATION

32 (0x20)

The process cannot access the file because it is being used by another process.

Probably something happened during application files transfer and an engine file remained locked. Try to redeploy it.

Conversion failure error 1260.

The error code is this:

ERROR_ACCESS_DISABLED_BY_POLICY

1260 (0x4EC)

This program is blocked by group policy. For more information, contact your system administrator.

Our tool launches a new process that renders the html. The application needs enough rights to do that.

During html to pdf conversion, web fonts sometimes do not appear or the text renders incorrectly.

This is usually a timing issue - the web fonts have not finished loading when the page is captured. Add a small delay before the conversion to allow the page more time to load its fonts:

converter.Options.ConversionDelay = 2;
Issue with web fonts on HTML to PDF conversion.

The Chromium engine loads and embeds the web fonts referenced by the page in the standard web font formats (WOFF2, WOFF, TTF, OTF). Make sure the font files are reachable from the page and that the page has time to load them (see the previous section about adding a load delay).

When a html string is converted to pdf, the styles are not applied and the images are missing.

When you convert a string to pdf and have references to external resources, the converter needs to know the location of the html. To do that you need to use the version of ConvertHtmlString method has also an additional parameter called baseUrl. Use that to specify the path where the file should be. Using it and the relative path to the image or css or js file from html, the converter will be able to calculate the full path to the resource file. ConvertHtmlString(String, String) contains an additional parameter: baseUrl. The baseUrl parameter allows the converter to resolve relative urls. Basically, baseUrl + relative image/css url = full absolute url.

I convert a web page to PDF and one of the images gets split between 2 pages. How do I make it stay in one page?

There are 2 solutions for this problem:

Solution 1: Put the CSS break-inside: avoid on the image, or on the element that contains it. The rendering engine paginates the page itself and honors that rule, so the image is moved whole to the next pdf page rather than being split. Applied to a single element it affects only that one; applied to img it keeps every image on the page together, which can leave large gaps where an image is nearly as tall as the page.

Solution 2: Modify the html and set the style page-break-inside: avoid on the img tag of the image that you need to stay in one page.

The "page-break-inside" property sets whether a page break is allowed INSIDE a specified element. The element can be anything (image, table, table row, div, text, etc).

XML
<div style="page-break-inside: avoid">
The content of this div element will not be split into several pages (if possible)
because "page-break-inside" property is set to "avoid".
</div>
HTML to PDF. Conversion error: Navigation timeout.

The error message is self-explanatory and the error can be caused by multiple things:

1. The web page takes a long amount of time to load. The default amount of time that SelectPdf waits for a page is 60 seconds. If the page takes longer to load, try to increase the timeout using the property NavigationTimeout property of the HtmlToPdfOptions object:

// instantiate a html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();

// set the page timeout (in seconds)
converter.Options.NavigationTimeout = 120;

2. The url of the web page being converted is not resolved on the server. We've seen cases with servers that were not able to resolve urls of the domains hosted on the same machine. Connect remotely to your server and check to see if the url is resolved.

3. You are using a proxy server to connect to the internet. SelectPdf Html to Pdf Converter supports this option and can convert web pages that can be accessed only though a proxy server. Use ProxyOptions property of the HtmlToPdfOptions object to setup your proxy.

HTML to PDF conversion fails on a minimal Linux server or container.

The Chromium engine renders headless (no X server or Xvfb is needed), but it depends on the usual Chromium system libraries. A desktop Linux distribution already has them; a minimal server or container image may not. Install the Chromium runtime dependencies (NSS, glib/gobject/gio, atk/at-spi, the X11 client libraries, gbm, cairo, pango, alsa, dbus, cups, expat, xkbcommon, udev), or place the bundled .so closure alongside the engine. See the deployment section.