FAQs
Q: My application is correctly working on the development server but on a production
server I get "The URL is not accessible." exception.
A: "The URL is not accessible" message is normally followed by a more detailed message
which should clearly indicate the root of the problem. Below is a general description
of the possible reasons of this error.
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, permissions
or authentication on the server.
First make sure the web page you are converting is accessible for converter. If
the page requires server authentication (like IIS authentication - Integrated Windows
Authentication) you can provide the correct Username and Password using the AuthenticationOptions
property of the PdfConverter.
If your application is using ASP.NET level authentication like Forms Authentication
the converter will not be able to authenticate because it doesn't send back to the
web server the authentication cookie created during the authentication process between
the browser and IIS. If using the forms authentication is a requirement for your
application you might try to configure your application to use the cookieless mode
for the forms authentication.
Other access restrictions can be introduced by proxy servers or firewalls. When
you access the web page from Internet Explorer for example it might work because
the proxy server settings are set in the Internet Options of the currently logged
user and browser will use those settings to authenticate to the proxy. When you
try to convert the same page from an ASP.NET application, the converter, which runs
under the ASP.NET user account, is not using the Internet Settings for the currently
loged in user and therefore it won't be able to authenticate to the proxy. Firewall
servers can be a similar source of access restrictions that you'll have to check.
If you are converting a https URL from your network you can try the same url with
http:// instead of https://. Running secured pages require a valid (not a self signed)
SSL certificate.
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 address instead of a domain
name.
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 you don't see any obvious reason for the web page to be inaccessible for the
converter 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 from your server. If this URL works
then the URL you are trying to convert might not be accessible indeed for the converter
and you should keep searching for the possible reasons. If it's not working it means
the converter is not allowed to access Internet under the ASP.NET user account and
you should further check proxy servers, firewalls, etc.
In general, because we don't know the exact network configuration of your server
or of your intranet, we cannot tell exactly which of the possible access problems
described above applies to your situation. You should carefully check the possible
situations described above and also check with your network administrator about
other possible access restrictions before going further.
If your are pretty sure there should be no access 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. 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 than the permissions under which the IE web browser 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 might be a permissions issue. You can temporary
add the ASP.NET user (determined as above) to Administrators group on the server
or you can use ASP.NET impersonation by adding the following line in the web.config
of your application under the <system.web> section : <identity impersonate="true"
userName="WindowsDomain\YourUserName" password="YourPassword"/>.
If the conversion works you can start looking into what exactly permissions the
converter needs from your server and grant those permissions to the 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. You can try to filter the messages by ASP.NET worker process
ID to substantially reduce the number of displayed messages. You might find for
example that the ASP.NET user cannot create files into the Internet Temporary Folder
where the images and CSS files are temporary downloaded or the ASP.NET user has
not enough rights to read the Internet Settings from Windows Registry.
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. We'll try to work
with you to localize the problem.
Q: When I convert a HTML string to PDF, the external CSS files and images are not
applied in the rendered PDF document.
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. This requires from the HTML string to have a valid HEAD
tag. When the relative paths of your images are textually prefixed with the baseURL
parameter the full URL of the images should be produce in order to start getting
images in PDF.
As an alternative you can manually insert a BASE tag in the HEAD tag of the HTML
page as in the example below or use full URLs in the HTML string:
<HEAD> <BASE
HREF="SiteURL"> </HEAD>
Note: This issue might also indicate an authentication or permissions
problem on the server when accessing the external resources like images and CSS
files. The HTML string is loaded into converter and the text is converted to PDF
but the images and CSS files are still accessed from an URL and they might not be
accessible.
If you are sure that the url base you have set is correct but the images still don't
appear in PDF you can try to prefix a relative image URL from the HTML string with
the the base url to construct a full image URL. Then you can put this url in the
IE web browser on the server where you perform the conversion and check that the
image is correctly displayed in the browser. After that you can try to convert the
image URL to PDF using the GetPdfBytesFromUrl() method. If the image is not accessible
you should get a "The URL is not accessible." error. See the question above regarding
the 'URL is not accessible' exception to find out more details about how to localize
and troubleshoot this problem.
Another special situation where this problem might occur is for ASP.NET applications
using forms authentication. The ASP.NET forms authentication implementation usually
stores the forms authentication ticket in a cookie which should be sent back to
server each time a resource is requested but the converter does not have the ability
to automatically send this kind of cookie back to the server and therefore the authentication
of the requests of external resources like images and CSS files can fail. A possible
workaround for this problm is to store the images and CSS files referenced by the
web page to be converted in a location which doesn't require authentication. If
this is not an acceptable solution then you can try to set the forms authentication
to the cookieless mode. In this mode the encrypted authentication ticket is set
in the URL query string and not in a cookie and the base URL parameter of the HTML
string convert function should be set accordingly to the URL containing the authentication
ticket. You can read more about forms authentication at the following address: Forms
Authentication Explained .
Q:
In rendered PDF document the images and text fonts appear to be smaller than they
are in the source HTML document. For other HTML documents the rendered content is
not shrunk but it appears in the left side of the document and is not centered.
How can I control this?
A: The ExpertPDF HTML to PDF converter allows a very fine control of the PDF rendering
process. The default settings of the converter should be acceptable for majority
of the situations but sometimes more control and customizations are necessary. If
want to learn more about the HTML to PDF rendering please check
this article.
The converter internally uses a virtual display where to render the HTML page very
similar to what the web browser does on the screen. This virtual display is different
from display of your computer and it has a fixed resolution on your computer (which
normally is 96 dpi) independent of the resolution of your computer screen. The web
page elements dimensions are usually measured in pixels and this is the reason why
the virtual display of the converter is also specified in pixels. These are the
only dimensions used by the converter which are expressed in pixels. All the other
dimensions are specified in points (1 point is 1/72 inches). However, because of
the fixed resolution of the virtual display, the pixels dimensions of your web page
can be easily converted to dimensions expressed in points . The converter API offers
the UnitsConverter class which can be used to convert dimensions from pixels to
points and from points to pixels.
You can specify the virtual display width and height in pixels using the PdfConverter.PageWidth
and PdfConverter.PageHeight properties or you can specify the same values as parameters
when you construct the PdfConverter object.
By default the PageWidth is set to 1024 pixels which should be sufficient to display
the majority of the web pages. If the web page you are converting cannot be completely
displayed in this width then you can increase this value or you can set the PageWidth
to 0 to allow the converter to automatically determine your web page width from
the HTML elements width. The PageHeight property is 0 by default which means the
virtual display will be automatically resized to display the whole HTML page. There
are situations when the converter cannot automatically determine the web page height
for example when the web page is a frame set. In this case you can manually set
the PageHeight to certain value in pixels such that the page is displayed in the
way you expect.
After the HTML content is displayed in the virtual display the virtual display content
will be transfered into PDF as you would take a picture of the virtual display and
put that picture into a PDF document. The PDF documents pages have a fixed size
in points. For example, the A4 page is 595 points in width and 842 points in height.
If the virtual display width is more than 595 points then the rendered HTML content
would be shrinked to fit the PDF page width and display the whole HTML content in
the PDF document. If the virtual display width is less than 595 points then
the rendered HTML content will not be resized and will be rendered in the top left
corner of the PDF page at real size.
The dimension of the A4 portrait page in virtual device pixels is 793x1122 pixels.
This means that at a default virtual display width of 1024 pixels the HTML content
will be shrunk to fit the PDF page. This is the reason why you see smaller fonts
and images in PDF.
In the version version 3.5.2 of the converter a new property FitWidth was added
to the PdfConverter.PdfDocumentOptions. The default value is true which makes the
HTML content to be resized if necessary to fit the PDF page width. When false, the
HTML content will not be resized and it will be rendered at the real size in PDF
(the size it has in the virtual display at the usual resolution of 96 dpi).
When the FitWidth property is false the HTML content could be wider than the PDF
page width and the therefore the HTML content will be cut off to the right in PDF.
In this case, in order to get the whole content in PDF you have to set a wider page
for the PDF document. You can first try to set landscape orientation for the PDF
page by setting PdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape.
If this not enough you can choose a wider standard page like A3 or A2. You can even
set a custom size for the PDF page. Starting with version 3.2 of the converter you
can set the PdfConvert.PdfDocumentOptions.PdfPageSize=PdfPageSize.Custom and in
this case the custom size of the PDF page will be taken from PdfConverter.PdfDocumentOptions.CustomPdfPageSize
property.
In version 4.0 of the HTML to PDF Converter product we added a new property PdfConverter.PdfDocumentOptions.AutoSizePdfPage
which is has effect only when the FitWidth property is false. When FitWidth is false
and AutoSizePdfPage is true, the PDF page width will automatically be resized to
a custom value such that all the HTML content is displayed in PDF at real size.
If you don't want to resize the PDF page but you want to keep it A4 portrait for
example, then you have to decrease the virtual display width. If your page can be
correctly and entirely displayed in 793 pixels (which is the width of the A4 portrait
page in pixels) you can set this value for PdfConverter.PageWidth property and you
should get the whole HTML rendered at real size in PDF.
The HTML content centering in PDF problem can be observed when the HTML content
can be normally displayed at a width less than 1024 pixels. In this case there will
normally be an empty space in the right side of the virtual display. When the virtual
display content is transfered to PDF the content will appear as not centered in
PDF. You can also solve this if you set the PdfConverter.PageWidth to a value of
793 pixels or less.
Q: Can
the converter be used with on 64-bit Windows servers?
A: Starting with version 3.5 the converter can run on all 64-bit Windows versions
both in 64-bit mode and 32-bit WoW mode.
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.
The converter library offers a set of methods for converting a HTML string to PDF.
See the WebLibrary_DynamicInvoiceDemo for a complete sample of
how to retrieve the HTML code and convert it to PDF.
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. This basically
happens because the converter does not send the session cookie from the browser
back to the server. 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.
See the InvoicesDemo application for ASP.NET for a complete sample
of how to retrieve the HTML code from a ASP.NET page, pass the session data to the
converted page and convert the HTML string to PDF. This application is also installed
as a live demo in our website.
Basically you have 2 options to consider when trying to overcome this situation
: to send the necessary data for loading the page to be converted in the query string
of the converted page URL or to get the web page HTML code using the Server.Execute(Url)
method as we do in the InvoicesDemo sample . 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 automaticallt 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 converter use during conversion the session cookies stored in the current
web browser session when the converter is called from an ASP.NET application?
A: The session cookies stored by the browser are not automatically sent to the web
server by the converter when the converter is called from an ASP.NET page.
Starting with the version 5.4 of the converter it is possible to send custom HTTP
headers when a page is requested from the web server. A cookie can be sent to the
web server using such a custom HTTP header. The syntax to configure the converter
to send a cookie to the web server is:
pdfConverter.HttpRequestHeaders = String.Format(
"Cookie : {0}={1}\r\n", cookieName, cookieValue
);
Q: Does the HTML to PDF converter support authentication when used in ASP.NET application?
A: The converter offers support for server authentication, for example any type
of IIS authentication (Integrated Windows Authentication, Basic Authentication,
etc). To enable server authentication you have to set the PdfConverter.AuthenticationOptions
property with the username and password. The server authentication is usually necessary
when accessing Intranet resources.
Please do not confound the server authentication with the authentication implemented
at the level of your application (usually implemented as a login page in your application
). If you need to deal with application level authentication please read below.
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. Also the converter does not have any
built-in support for authentication.
You have 2 options to consider when trying to overcome this situation : to
send the necessary data for loading the page to be converted in the query string
of the converted page URL or to get the web page HTML code using the
Server.Execute(Url) method from ASP.NET and then convert that string
to PDF as we do in the dynamic invoices sample. The Server.Execute() method is executed
in your application session so all the session data and existing authentication
should be valid.
See the InvoicesDemo application for ASp.NET for a complete sample
of how to retrieve the HTML code, pass the session data to the converted page and
convert the HTML string to PDF.
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 insert a page break in the resulted PDF document?
A: The HTML to PDF converter supports custom page breaks with standard CSS styles
like page-break-before:always and page-break-after:always
applied to any HTML object. The page-break-inside:avoid style can
be applied to a element to prevent splitting the content inside the element between
pages.
Q: How can I specify to the converter to not break (keep together on the same page)
a HTML region between PDF pages?
A: You can apply inline the page-break-inside:avoid
CSS style to the HTML element you want to keep appear in the rendered PDF document
on same page. Of course the element height must be less than the page height, otherwise
the style will be ignored by the converter. Please note that unlike the page-break-before
and page-break-after , the page-break-inside:avoid
style must be specified inline as in the example below:
<table>
<tr style="page-break-inside : avoid">
<td>
<img width="100" height="100" src="img1.jpg">
</td>
<td>
My text 1
</td>
</tr>
<tr style="page-break-inside : avoid">
<td>
<img width="100" height="100" src="img2.jpg">
</td>
<td>
My text 2
</td>
</tr>
</table>
In this example the table can contain a large number of rows, each row containing
an image in the left and a text in the right and we don't want such a row to span
on two pages. This can be easily achieved by specifying the page-break-inside:avoid
style inline for the table row.
Q: Can the converter render a HTML string or an URL in the header and footer of
the generated PDF document?
Q: Is it possible to have different content in the header (or footer) of different
PDF pages?
Q: How can I add many HTML documents into the same PDF document?
A: Starting with version 5.1 it is possible to add many HTML documents to the same
PDF document using the PostConvertActionEvent feature and we provide the MultipleHtmlConversions
sample both for ASP.NET and Windows Forms to show how to do this. The first document
is added to PDF using the usual methods like GetPdfBytesFromUrl() or GetPdfFromHtmlString().
The other documents are added in the PostConvertActionEvent handler as HtmlToPdfElement
objects. You can add a HtmlToPdfElement on a new PDF page or you can continue right
after the point where the rendering of the first HTML document ended. The 'Start
second URL conversion on a new PDF page' checkbox in the sample application controls
this. You can find where the first document finished rendering from the ConversionSummary
property of the argument passed to the event handler. If you want to add many HtmlToPdfElement
objects one after the other, you can find where a HtmlToPdfElement finished rendering
from the AddElementResult object returned as result of adding the HtmlToPdfElement
object to the PDF page and you can start the next HtmlToPdfElement object from that
position.
Q: Can I disable the HTTP links from the generated PDF document?
A: The PdfConverter.PdfDocumentOptions.LiveUrlsEnabled controls the rendering of
http links in the resulted PDF document. By default this property is true.
Q: What type of fonts does the converter support and how can I embed the fonts in
the generated PDF document?
A: The converter supports any true type font preinstalled in Windows operating system.
It also supports the open type fonts with the condition that the open type font
has TrueType outlines not PostScript outlines. To check what type of outlines has
an installed font, you can open the font from the Fonts folder in Control Panel.
When a font is not supported by the converter the MS Sans Serif font is used by
default.
The converter also supports custom true type fonts you can install from a .ttf or
a .otf file. After you have installed a font it becomes available only for the currently
logged in Windows user who installed the font. In order to make the font available
for all the users, including the ASP.NET user in the case you are using the converter
from an ASP.NET application, you have to reboot the computer after font installation.
To embed the true type fonts in the generated PDF you have to set PdfConverter.PdfDocumentOptions.EmbedFonts=true.
By default this property is false. The same property is also available in the HtmlToPdfElement
class defined by the PDF Creator and HTML to PDF Converter libraries.
Q: Some images are cut off between PDF pages? Is there any option to avoid this?
A: Set the PdfConverter.AvoidImageBreak property on true. By default this property
is false and the images might get cut off between PDF pages. You can also set the
page-break-inside:avoid CSS style inline on the IMG tag to achive the same result.
Q: How can I control the images quality in PDF?
A: By default the the converter is using JPEG to compress images in PDF and to reduce
the size of the generated PDF document. The compression level of the images is controlled
by the PdfConverter.PdfDocumentOptions.JpegCompressionLevel property. When the JpegCompressionLevel
is 0, the compression rate is the lowest and the quality of the images is the best.
When the JpegCompressionLevel is 100, the compression rate is the highest and quality
of the images in PDF is the worst. The default JPEG compression level is 10, which
should offer a good balance between the compression rate and the quality of the
images in PDF.
It is also possible to completely disable the JPEG compression and store the images
as bitmaps in PDF if you set PdfConverter.PdfDocumentOptions.JpegCompressionEnabled
to false. This produces the best quality of the images but the generated PDF document
can be very large and the conversion process is slower.
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.
If you already set the PdfConverter.ScriptsEnabled on true and the JavaScript code
is still not executed it means the Internet Security Settings on your server don't
allow the JavaScript execution. JavaScript code could work when you load the page
in Internet Explorer because the browser runs under the currently logged in user
and for this user the JavaScript execution is allowed by the Internet Security Settings
for the security zone of the page you are trying to convert. When you run the converter
from an ASP.NET application the JavaScript execution might not be allowed for the
ASP.NET user and for the security zone of the web page you are converting. A simple
thing you can do is to move the web page in a more permisive Internet Security Zone
like Local Machine. You can achieve this if you set the PdfConverter.InternetSecurityZone
property with the InternetSecurityZone.LocalMachine value. If it's still not working
you might have to modify directly into the Windows Registry the ASP.NET user Internert
Security profile to allow JavaScript execution. The following technical article
from Microsoft shows how to configure the internet security zones registry, including
the JavaScript and ActiveX execution.
Internet Explorer security
zones registry entries
The key 1400 in each security zone should be set to 0 both in HKEY_LOCAL_MACHINE
and in HKEY_USERS for the user running the converter. After you have modified the
registry you have to reboot the computer to make sure the new configuration is applied.
Q: The flash images and ActiveX controls are not rendered in the PDF document. Is
there any option I should set?
A: The flash images and movies are rendered by an external flash player which is
an ActiveX control. First you have to make sure a flash player is installed on your
server and the flash image or movie is displayed when the web page is loaded in
the IE browser running on your server without any warnings. Then you have set the
PdfConverter.ActiveXEnabled=true when converting to PDF with selectable text or
PdfConverter.ActiveXEnabledInImage=true when converting to PDF with embedded image.
Please note that the converter could automatically switch to a PDF with embedded
image when ActiveXEnabled property is true. Sometimes the ActiveX control are written
in HTML using JavaScript. In this case the JavaScript execution should also be enabled
during conversion as explained in the answer to the previous question.
If you already activated ActiveX controls during conversion but your flash image
still doesn't appear in PDF or is empty then this probably happens because
the flash control did not finish to initialize the image when the converter detected
the web page was completely loaded. You can try to manually set a delay before starting
the PDF conversion using the PdfConver.ConversionDelay and setting it to a small
value in seconds (you can start with a 3 seconds delay for example).
If the flash images still don't appear in PDF it means the Internet Security Settings
on your server don't allow the ActiveX execution. The ActiveX can work when you
load the page in Internet Explorer because the browser runs under the currently
logged in user and for this user the ActiveX execution is allowed by the Internet
Security Settings for the security zone of the page you are trying to convert. When
you run the converter from an ASP.NET application the ActiveX execution might not
be allowed for the ASP.NET user and for the security zone of the web page you are
converting. A simple thing you can do is to move the web page in a more permisive
Internet Security Zone like Local Machine. You can achieve this if you set the
PdfConverter.InternetSecurityZone property with the InternetSecurityZone.LocalMachine
value. If it's still not working you might have to modify directly into the Windows
Registry the ASP.NET user Internert Security profile to allow ActiveX execution.
The following technical article from Microsoft shows how to configure the internet
security zones registry, including the JavaScript and ActiveX execution.
Internet Explorer security
zones registry entries
The key 1200 in each security zone should be set to 0 both in HKEY_LOCAL_MACHINE
and in HKEY_USERS for the user running the converter. After you have modified the
registry you have to reboot the computer to make sure the new configuration is applied.
Q: Which Adobe Reader versions can read the generated PDF documents?
A: The converter generates PDF documents in conformance with PDF 1.4 specification.
This specification is fully supported starting with Adobe Reader 5.0.
Q: Can I open the generated PDF document directly into a browser window instead
of displaying the Open/Save dialog in browser?
A: Instead of the code from our samples which sends the PDF bytes to the browser
as an attachment you can use the following code to open the generated PDF document
inline:
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Type", "application/pdf");
response.AddHeader("Content-Disposition",
"inline; filename=" + downloadName + "; size=" + downloadBytes.Length.ToString());
response.Flush();
response.BinaryWrite(downloadBytes);
response.Flush();
response.End();
Q: Can I append external PDF documents to the PDF document resulted after conversion?
A: You can add external PDF files and streams to the conversion result using the
AppendPDFFile, AppendPDFFileArray, AppendPDFStream and AppendPDFStreamArray properties
of the PdfConverter.PdfDocumentOptions. You can find a full sample of how to use
these properties under the 'WinForms_PrependAppendExternalPdfs' sample from the
downloaded archive. If you need more flexibility in merging conversion results with
external PDF documents then you can try our PDF Merge library which is a separate
product.
Q: Can I specify a custom PDF page size for the generated PDF document?
A: Starting with version 3.2 of the converter you can set the PdfConvert.PdfDocumentOptions.PdfPageSize=PdfPageSize.Custom
and in this case the custom size of the PDF page will be taken from PdfConverter.PdfDocumentOptions.CustomPdfPageSize
property where you can specify the width and height of the PDF page in points.
Q: How can I use the HTML to PDF converter library from .NET 1.1 applications or
from PHP applications?
A: The HTML to PDF converter library is a .NET 2.0 library and it is not working
with .NET 1.1 directly. The workaround for this is to create an HTML to PDF Converter Web Service
which exposes a simple method to return the rendered PDF document bytes from
a specified URL. The web service internally should make calls to the converter library.
Note: Another possible solution is to create a .NET 2.0
command line tool to be called from your application but there might be some additional
overhead with this approach to execute the command line and retrieve the generated
PDF document. We provide a sample console application Console_HtmlConvertDemo_CS
in the HTML to PDF Converter archive that might be a good starting point.
Q: How do I perform a conversion to Landscape page orientation?
A: Use the following property:
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape;
Q:
When I converted a web page containing a frameset tag only the top part of the page
was rendered in PDF.
A: This indicates the converter was not able to correctly determine the height of
the web page. The work around is to explicitly set the web page in pixels or to
convert directly the web pages referred by the frameset frames. For example you
can set pdfConverter.PageHeight = 2000;
Q: Can I deploy my ASP.NET application using the HTML to PDF Converter on a shared
server?
A: The converter requires Full Trust level for the ASP.NET application calling it.
The default trust level for an ASP.NET applications is Full Trust but the shared
hosting providers usually modify the trust level to Medium Trust which makes our
converter to not run properly in such environments. In order to solve this issue
you can ask you shared hosting provider to give Full Trust level for you ASP.NET
application. Another possibility is to create a ASP.NET web service around the converter
library, install that web service on a machine where the full trust is allowed and
call the web service from your application. You have to ensure that the web service
you create can be used only from your application.
Q:
The exception "Could not get image from url. Could not initialize the html converter
object.Request failed.." or the exception "Required permissions cannot be acquired."
or the exception "Operation could destabilize the runtime" is thrown during the
HTML to PDF conversion.
A: The converter needs a full trust level for your ASP.NET 2.0 application in order
to correctly execute. The default trust level is full but some of the hosting providers
set this to medium or lower. The trust level can be set in the Web.config of the
application ( <trust level="Full"/> under the <system.web> config section
) but the hosting provider could also forbid overriding the trust level from the
web site configuration file.
If your application already has full trust that means more security restrictions
are imposed by the Windows to the assembly. Adding the assembly to the GAC (Global
Assembly Cache) usually makes the assembly more trusted and solves the problem.
A special situation when this exception can occur is on Windows Vista family of
operating systems (Windows Vista SP2, Windows 7). When you download the assembly
from Internet the operating system marks the file as "Blocked". You can check the
assembly was blocked if you right click on the file in Windows Explorer and select
Properties. At the bottom of the Properties tab there should be an "Unblock" botton
if the assembly was blocked and the message "This file came from another computer
and might be blocked to help protect this computer" should be displayed near that
button. To unblock the assembly and allow its execution simply click the "Unblock"
button and restart the IIS application pool of your application to make sure the
change was applied.
Another solution in this situation is to change the identity of the IIS pool of
your application to a less restrictive account. The Network Service account should
normally allow the execution of the assembly.
Q: The
HTML to PDF converter throws the following exception: "HtmlConvertException: Could
not generate the PDF document. Could not get image from url. Could not initialize
the html converter object. Access is denied. (Exception from HRESULT: 0x80070005
(E_ACCESSDENIED))."
A: This error indicates the WebBrowser control could not access the COM interface
of the Internet Explorer. You can try to use the dcomcnfg utility to allow the user
running the application to access the interface. In Start->Run type dcomcnfg and
under Component Services -> Computers -> My Computer -> DCOM Config select Internet
Explorer. Right click on it and from tabbed properties select Security. To customize
the access permissions select Customize radio button and give access to the user
running the application ( for ASP.NET this should be the IUSR_{MACHINE_NAME} if
your application is using impersonation to execute )
Q: The converter throws an "Out of memory" exception or a "Parameter is not valid"
exception under some circumstances.
A: This defect was fixed in version 3.6.2 of the converter. If the problem persists
with the latest version please contact support by email and provide the HTML document
and the test application for which this problem occured.
The workaround you can try is to set PdfConverter.BatchConversion=true and make
sure the converter is called from a STAThread. If you are using the converter from
a console application the Main function of the console application has to be assigned
with the [STAThread] attribute. In the Windows Forms applications the main thread
of the application is a STA thread. If you call the converter from a ASP.NET page
then you can set the AspCompat="true" attribute on @Page directive of the .aspx
page.
As an alternative you can create a new thread to run the conversion loop and call
SetApartmentState(ApartmentState.STA) against the Thread object before starting
the thread.