Opens an HTTP URL and converts the content of the page into PDF.
Populates the current PdfDocument object with the result of the conversion.
The current PdfDocument can either be an empty document created with CreateDocument, or an existing
document opened via OpenDocument/OpenDocumentBinary.
Return value: if the Debug parameter (see below) is set to True, this method returns a log
of non-fatal errors. Otherwise returns an empty string.
URL can be an http or https address, such as "http://www.server.com/path/file.asp",
or a physical local path such as "c:\path\file.html". It can also directly specify an HTML
text string, such as "<html>some HTML code</html>".
For more information about this method, see Chapter 13 - HTML to PDF Conversion.
Param is a PdfParam object or parameter string specifying various conversion parameters
(all of them optional), including:
- PageWidth - page width, 612 (8.5") by default.
- PageHeight - page height, 792 (11") by default.
- Landscape - if set to True, the document's pages have landscape orientation.
False (portrait orientation) by default.
- LeftMargin, RightMargin, TopMargin, BottomMargin -
page margins, 54 (0.75") by default.
- LeftMarginNNN, RightMarginNNN, TopMarginNNN, BottomMarginNNN -
page margins specified individually for page number NNN. Override the default margin settings.
Pages with numbers higher than NNN inherit the new settings.
The effective page width must be kept unchanged, i.e. the value PageWidth - LeftMarginNNN - RightMarginNNN
(or in case of Landscape=true, PageHeight - TopMarginXXX - BottomMarginXXX) must be the same for all pages.
These parameters were introduced by
version 1.6.0.10.
- CodePage - specifies the encoding of the page, similar to the View/Encoding option in a browser.
This parameter, if specified, overrides the charset value
specified via a <META http-equiv="Content-Type"> tag in the document's body.
1252 (US ASCII) by default.
- StopAfter - specifies the number of pages in a resultant document after which
the document creation will be aborted, with an error message added to the log (see the Debug parameter below.)
200 by default.
- DrawBackground - if set to True, each page of the generated PDF document
will display a background specified by the source HTML document's BGCOLOR or BACKGROUND
attributes (or their CSS equivalents BACKGROUND-COLOR and BACKGROUND-IMAGE.) False by default, which means the background
remains transparent/white regardless of the source HTML document's background settings.
- StartPage - specifies the 1-based index of a page to begin rendering on. Applies
to non-empty documents only. If the specified value is greater than the number of pages in the current document,
the rendering will begin on the last page of the document. 1 by default.
- Hyperlinks - if set to True, all hyperlinks on the page being converted
will be enabled (clickable). False by default. This parameter was introduced by version 1.7.
- Media - specifies which cascading style sheets
to read depending on their MEDIA attribute. Can be a combination (sum) of the following
values: 1 ("all"), 2 ("screen"), 4 ("print"), 8 ("asppdf") and 128 (all others.)
255 by default, which means the MEDIA attribute is ignored altogether.
This parameter was introduced by version 1.7.
- Scale - specifies a scaling factor at which the document is rendered.
1 by default which means 100%. A number less than 1 shrinks the document, greater than 1
expands it. This parameter was introduced by version 1.7.
- SplitImages - by default, if the bottom part of an image cannot fit on the page,
the whole image is pushed down to the next
page to preserve its integrity. If this parameter is set to True, an image may be split between
adjacent pages
if necessary. False by default.
This parameter was introduced by version 1.7.
- Debug - if set to True, the method returns a log of non-fatal errors
encountered during the HTML to PDF conversion process,
such as invalid image URLs, unknown fonts, etc. False by default.
This parameter should be used for debugging purposes only.
- Timeout - if set to a positive number, specifies the timeout value (in seconds)
for the Resolve, Connect, Send and Receive HTTP operations (same value for all four operations.) By default, these
timeout values are 0 (infinite), 60 seconds, 30 seconds and 30 seconds, respectively.
This parameter was introduced by version 1.7.
- InvertCMYK - if set to True, inverts all CMYK images on the HTML document back to normal.
False by default. This parameter was introduced in version 2.0.0.7.
Username, Password specify authentication parameters in case the URL
is protected with basic authentication. These arguments can also be used to pass
the authentication cookie name (prefixed with the word "Cookie:") and cookie value
when using .NET Forms authentication. This is described in detail in
Section 13.2 - Authentication.
Usage:
' Create a new PDF document from a URL, use Landscape mode, enable hyperlinks
Set Doc = Pdf.CreateDocument
Doc.ImportFromUrl "http://www.server.com", "landscape=true, hyperlinks=true"
Doc.Save "c:\path\doc.pdf"
' Create a new PDF document from a local HTML file, enable logging
Set Doc = Pdf.CreateDocument
LogString = Pdf.ImportFromUrl( "c:\path\doc.htm", "debug=true" )
Doc.Save "c:\path\doc.pdf"
' Render HTML from a URL onto an existing PDF document starting with page 2
Set Doc = Pdf.OpenDocument( "c:\path\template.pdf" )
Doc.ImportFromUrl "http://www.server.com/path/file.asp", "startpage=2"
Doc.Save "c:\path\doc.pdf"
' Use direct HTML feed. The argument string must contain "<html>"
Set Doc = Pdf.CreateDocument
Doc.ImportFromUrl "<html><table><tr><td>...</td></tr></table>"
Doc.Save "c:\path\doc.pdf"