FAQs about ExpertPDF HtmlToPdf Converter
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: How can I add more complex headers and footer? Does your application support HTML in header/footer?
A: Our component does not support HTML in header/footer. There are a number of options related to headers/footers. You can add a title, a subtitle and an image.
If this is not enough for you and you need html in the header/footer, you can generate an image from a html string with our html to image converter (included with the html to pdf converter in the same dll)
and you can add the generated image in the header/footer.