Read the following sections to learn how to fix common problems that might appear when using SelectPdf library for .NET:
SelectPdf Html To Pdf Converter from Select.Pdf library for .NET needs 3 files to work: the .NET assembly Select.Pdf.dll and 2 additional files (Select.Html.dep and Select.Tools.dep). These 2 additional files, because they do not have a reference in the project, might not get copied to the deployment destination. To fix the problem, copy them manually. More details about this in the deployment section.
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, if you use an x64 system, you can use SelectPdf x64 optimized version that allows the allocation of a lot more memory than the default x86 version.
The error code is this:
Access is denied.
Enable execute permissions on Select.Html.dep.
The error code is this:
The process cannot access the file because it is being used by another process.
Probably something happened during application files transfer and Select.Html.Dep remained locked. Try to reupload it.
The error code is this:
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.
This problem should be fixed in v17.1 version. For older versions, try the following solutions:
Solution 1: It could be just a matter of web fonts being loaded. Try to add a delay before the conversion to allow the page more time to load:
Solution 2: It could be something related to fonts caching. By default SelectPdf caches fonts in memory, but on some systems, the current problem might happen. The workaround is to cache fonts on the filesystem:
If you are using web fonts in your web pages, make sure you provide either TTF or WOFF versions for them, as these are the only 2 web font types supported by SelectPdf.
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.
There are 2 solutions for this problem:
Solution 1: Set the KeepImagesTogether to True. This property instructs the converter whether to try to avoid cutting off the images between pdf pages or not. Due to the fact that images could be large and avoiding cutting them would great large gaps in the pdf pages, the default value for this property is False. Please note that using this solution will make all images from the web page to stay in the same PDF page and not get split.
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).
<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>
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 MaxPageLoadTime property of the HtmlToPdfOptions object:
// instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set the page timeout (in seconds) converter.Options.MaxPageLoadTime = 120;
' instantiate a html to pdf converter object Dim converter As New HtmlToPdf() ' set the page timeout (in seconds) converter.Options.MaxPageLoadTime = 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.
4. You are using an Azure website and an older version of SelectPdf library. Older versions of SelectPdf only work on Azure if you deploy to a Cloud Service or Virtual Machine.