HTML to PDF Conversion - Technical Articles
HTML to PDF Conversion - Questions and Answers
Q: My application is correctly working on the development server but on a production
server I get "The URL is not accessible." 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, 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 from your intranet might require
some sort of credentials which are not send by the converter when it runs under
the ASP.NET account.
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.
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. 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 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: 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: Can
the converter convert HTML pages in RTL languages like Hebrew and Arabic?
A: When converting a HTML page in a RTL language you have to set the PdfConverter.RightToLeftEnabled=true.
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 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.
The custom page breaks work only when converting to a PDF with selectable texts
and objects. It is not working when you convert to a PDF with embedded image. You
can switch between the two modes with PdfConverter.PdfDocumentOptions.GenerateSelectablePdf
flag. When true, which is the default option, the converter will produce PDF documents
with selectable texts and objects.
The main goal of the converter is to preserve the exact aspect of the converted
web page. Under some situations (for example when using CSS filters like alpha,
blur, chroma, etc to add special effects for texts, images and backgrounds) the
converter will automatically switch to embedded image mode. In this case the custom
page breaks will not take effect.
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: 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: How can I embed the true type fonts in the generated PDF document?
A: If you set PdfConverter.PdfDocumentOptions.EmbedFonts=true, the true type fonts
will be embedded in the generated PDF document. By default this property is false.
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: 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.
Q: The flash images 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.
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.
Q: Which Adobe Reader versions can read the generated PDF documents?
A: The converter generates PDF documents in conformance with PDF 1.5 specification.
This specification is fully supported starting with Adobe Reader 6.0. To make the
generated PDF compatible with Adobe Reader 5.0 you can set PdfConverter.UseCrossRefStreams
property on false. Setting this property on false might slightly increase the PDF
document size.
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_ConvertAndMergePdf' 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:
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 Winnovative 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 is necessary.
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: 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 download and install our HTML to PDF Converter Bridge Web Service
which exposes a simple method to return the rendered PDF document bytes from
a specified URL. The web service internally makes calls to the converter library.
The downloaded archive also contains a ASP.NET 1.1 and a ASP.NET 2.0 test web sites.
The bridge web service must be installed on your server as any .NET 2.0 web service.
Most of the Windows servers today have the .NET 2.0 already installed or you can
download and install the
.NET Framework 2.0 Redistributable package for free from Microsoft web site.
To install our html to pdf converter web service on your server you have to create
a virtual IIS folder named ConvertWebService for the ConvertWebService folder from
the downloaded archive (the simplest way to to do this is to right click on the
folder and from the Properties page select the Web Sharing tab). Then you have to
make sure that the web service runs under ASP.NET 2.0 in IIS and also make sure
the security settings allows you to access the web service from your application.
From the IIS right click on the ConvertWebService web site and edit the Directory
Security and ASP.NET tabs.
Then all you have to do is to add a reference to the web service in your .NET 1.1
application and call the web service render method. You can extend our sample web
service with other methods allowing you to specify more options for the converter.
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:
I have deployed ASP.NET 2.0 application on a shared server and I receive an error
like this: "Winnovative.WnvHtmlConvert.HtmlConvertException: Could not get image
from url. Could not initialize the html converter object.Request failed.."
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.
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
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. In the downloaded archive under the
'WinConsole_HtmlBatchConversion' sample you can find a code sample. In this sample
the Main function of the console application was set 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.