ExpertPDF Components: Pdf Creator, HtmlToPdf Converter, Pdf To Text, PDF Merge, PDF Split, PDF Viewer

Frequently asked questions

Read the answers to the most frequently asked questions about ExpertPDF Tools: HTML To PDF Converter for .NET and PDF Merge Tool.

 
  Download   Buy now   Live demo    About us  

FAQs

Q: My HTML contains images and CSS styles in an external file. Will ExpertPDF be able to export this to PDF correctly?

A: Yes, ExpertPDF Html To PDF will export all your images and css styles if they are accessible when you open your page in a browser.


Q: How do I insert a page break?

A: You can use the following CSS styles:
page-break-before:always or page-break-after:always.

One note: Page breaks only work if you have the following property set:

pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;


Q: How do I enable support for right-to-left languages?

A: Set following property set:

pdfConverter.RightToLeftEnabled = true;

Note: You must have the specific language support installed on your computer (to check this, go to Control Panel > Regional and Language Options > Languages and make sure that the checkbox Install files for complex script and right-to-left languages is checked).


Q: Sometimes when I try to export a page to pdf, all the text in the pdf file is displayed on a column aligned to the left. The right half of the page is blank.

A: ExpertPDF Html To PDF Converter tries to automatically detect the width of your HTML page. Sometimes this does not work and you need to manually set the page width like this:

pdfConverter.PageWidth = 800;


Q: How can I obtain the HTML string from a web page and convert it to PDF?

A: If you are trying to convert a ASP.NET page you can use the Server.Execute method from to obtain the HTML string. Here is some C# code to obtain the HTML string from a page of your application:

StringWriter sw = new StringWriter();
Server.Execute("PageToConvert.aspx", sw);
string htmlCodeToConvert = sw.GetStringBuilder().ToString();


You can also use the methods from ConverterUtils class that we provide in the library to get the HTML code from a web page from Internet:

string htmlString = ConverterUtils.GetHtmlFromUrl(url);


Q: When I convert a HTML string that I obtained from a web page, the external CSS files and images are not displayed. What can I do?

A: When you convert a HTML string referencing external CSS files and images by relative URLs, the converter cannot determine the full URLs just looking at the string.

In order to solve this you have to set the baseURL parameter of the HTML string convert function with the full URL of the page from where you have retrieved the HTML string:

byte[] pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString, urlBase);

As an alternative you can also manually insert a BASE tag in the HEAD tag of the HTML page:

<HEAD> <BASE HREF="SiteURL"> </HEAD>


Q: Is the ASP.NET session data available in the converted ASP.NET page during conversion?

A: The converter executes the web page to be converted in a new session, different from the session in which your ASP.NET application runs. Therefore, the data currently stored in the session is not available in the converter web page even if the page is part of your application.

You have 2 options to work around this situation:

(1) send the necessary data for loading the page to be converted in the query string of the converted page URL

or

(2) get the web page HTML code using the Server.Execute(Url) method. The Server.Execute method is executed in your application session so all the session data and existing authentication should be valid.

When getting the HTML string with the Server.Execute(Url) method the resulted HTML code should reference the external CSS, images and JavaScript code by a full URL not by a relative URL. Here is some C# code to obtain the HTML string from a page of your application:

StringWriter sw = new StringWriter();
Server.Execute("PageToConvert.aspx", sw);
string htmlCodeToConvert = sw.GetStringBuilder().ToString();


To instruct the converter how to automatically turn all the relative URLs into absolute URL you have to pass the baseURL parameter of the convert function with the full URL of the page from where you have taken the HTML string.


Q: Does the HTML to PDF converter support authentication when used in ASP.NET application?

A: The converter executes the web page to be converted in a new session, different from the session in which your ASP.NET application runs. Therefore, the data currently stored in the session is not available in the converter web page even if the page is part of your application.

You have 2 options to work around this situation:

(1) send the necessary data for loading the page to be converted in the query string of the converted page URL

or

(2) get the web page HTML code using the Server.Execute(Url) method. The Server.Execute method is executed in your application session so all the session data and existing authentication should be valid.

When getting the HTML string with the Server.Execute(Url) method the resulted HTML code should reference the external CSS, images and JavaScript code by a full URL not by a relative URL. Here is some C# code to obtain the HTML string from a page of your application:

StringWriter sw = new StringWriter();
Server.Execute("PageToConvert.aspx", sw);
string htmlCodeToConvert = sw.GetStringBuilder().ToString();


To instruct the converter how to automatically turn all the relative URLs into absolute URL you have to pass the baseURL parameter of the convert function with the full URL of the page from where you have taken the HTML string.


Q: How do I perform a conversion to Landscape page orientation?

A: Use the following property:

pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape;


Q: I have deployed my project on the production server and I receive an error like this: "Could not get the metafile from url. Could not get image from url.Could not load file or assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.."

A: You need Microsoft.mshtml.dll on your server. Click here to download this dll. Place it in the bin folder of your application.


Q: Does ExpertPDF support .NET 1.1 ?

A: Our component does not support directly .NET 1.1. However, a large number of customers are using the following workaround: they have created a .NET 2.0 web service that wraps around ExpertPdf library, and they call this web service from their .NET 1.1 applications. Contact us if you need more details about this.


Q: My application is working on the development server but on a production server I get a "The URL is not accessible." exception or the "Get web page content cancelled or invalid URL supplied." exception.

A: If the application works correctly on your development machine but it's not working on the server then it's very likely to be an issue related to security and permissions on the server.

The development servers have a more relaxed internet security configuration then the production servers. For example the Windows 2003 Server defaults to an internet security configuration which may not allow you to access the URL. You may have to relax or disable the enhanced security configuration to allow access to the pages you want to render. If removing the internet enhanced security configuration component is an option, you can do so from the "Add/Remove Windows Components" section of the "Add or Remove Programs" control panel. The internet enhanced security configuration component should be listed as "Internet Explorer Enhanced Security Configuration".

If disabling the enhanced security for internet did not solve the problem then to further troubleshoot this first make sure the web page you are converting is accessible for converter. If the page requires server authentication (like IIS authentication) please provide the correct Username and Password using the AuthenticationOptions property of the PdfConverter. Firewalls and proxy servers can be another source of access restrictions that you'll have to check.

If it's not an authentication problem then make sure the web page you are trying to convert can be correctly loaded in the Internet Explorer browser running on your server while you are logged in as Administrator. Make sure IE does not block the URL or throws any warnings when loading that page. It is also possible, when converting a web page hosted on the server where you are performing the conversion, that the server cannot resolve the site name to an IP address. To eliminate this possibility try to use an IP instead of a domain name. To completely eliminate the possibility of an inaccessible URL, try to convert a HTML file from the server disk instead of an URL. You can simply pass to the converter the full path of the HTML file instead of the URL. If it works with a local HTML file then you can further try with an url like http://www.google.com which is likely to be available and accessible. If this URL works then the URL you are trying to convert might not be accessible indeed and you'll have to find the reason with your server administrator.

If none of the recommendations above helped, then try to find a permissions issue. The converter runs with the permissions granted to the ASP.NET user which are normally much lower then the permissions under which the IE web broser application runs. You can find out the ASP.NET user under which the converter is running by adding the <%= Environment.UserName %> line in the .ASPX from where the converter is called. The user name should be displayed when the .ASPX page is loaded in browser.

To make sure it's a permissions issue try to convert the same HTML page using the Free HTML to PDF Converter Windows Forms Application that we provide as a separate download or the one that you have built from the samples folder. This Windows Forms application will run as the currently logged in user, preferable an Administrator. If this application works then it is a permissions issue. You can temporary add the ASP.NET user (determined as above) to Administrators group on the server. If the conversion works you can start looking into what exactly permissions the converter needs from your server and add those permissions to ASP.NET user.

A useful tool for finding permissions issues is the Process Monitor. You can download this tool from Microsoft web site. The ProcessMonitor will monitor every file and registry access on your machine in real time. You have to start the tool and then make the issue to occur. You should look for suspicious FAILURE and ACCESS DENIED messages.

If you have followed all the steps above and you could not find the reason of the problem please contact us with the result of all these steps. This will save a lot of our and your time.


Q: The JavaScript code from HTML page is not executed during conversion. How can I activate JavaScript code execution during conversion?

A: The PdfConverter has the following properties controlling the JavaScript, Java Applets and ActiveX download and execution during conversion: ScriptsEnabled, ScriptsEnabledInImage, ActiveXEnabled, ActiveXEnabledInImage. By default these properties are false which means the JavaScript code is not enabled during conversion. To activate JavaScript simply set PdfConverter.ScriptsEnabled = true when converting to PDF with selectable text or set PdfConverter.ScriptsEnabledInImage = true when converting to PDF with embedded image.

Latest news

Jun 18th, 2008
ExpertPDF Pdf Creator v2.3.0 was released. more details

Jun 18th, 2008
ExpertPDF HtmlToPdf Converter v2.9.0 was released. see what's new

New tools:
RTF To PDF
PDF Security
PDF Images Extractor




"HTML to PDF is a quality component that is clearly valuable to any Web developer in need of an easy and flexible way to generate PDF files."

Steve C. Orr - MCSD, Microsoft MVP in ASP.NET


more testimonials
customers list


PDF Library Pdf Software Html 2 Pdf Html To Pdf API C# ASP.NET To Pdf Pdf Developer Tools

Copyright 2008. ExpertPDF Components. ExpertComponents.com.