Loading...
Searching...
No Matches
pdftron::PDF::HTML2PDF Class Reference

`#include <HTML2PDF.h>`

## Public Types
typedef pdftron::PDF::Proxy | Proxy
typedef pdftron::PDF::WebPageSettings | WebPageSettings
typedef pdftron::PDF::TOCSettings | TOCSettings

## Public Member Functions
void | InsertFromURL (const UString &url)
void | InsertFromURL (const UString &url, const WebPageSettings &settings)
void | InsertFromHtmlString (const UString &html)
void | InsertFromHtmlString (const UString &html, const WebPageSettings &settings)
void | InsertTOC ()
void | InsertTOC (const TOCSettings &settings)
bool | Convert (PDFDoc &doc)
int | GetHTTPErrorCode () const
void | SetQuiet (bool quiet)
void | SetCompatibilityMode (bool compatibility)
void | SetSandbox (bool sandbox)
void | SetLogFilePath (const UString &path)
UString | GetLog () const
| HTML2PDF ()
| ~HTML2PDF ()
void | SetPaperSize (PrinterMode::PaperSize size)
void | SetPaperSize (const UString &width, const UString &height)
void | SetLandscape (bool enable)
void | SetDPI (int dpi)
void | SetOutline (bool enable, int depth=4)
void | DumpOutline (const UString &xml_file)
void | SetPDFCompression (bool enable)
void | SetMargins (const UString &top, const UString &bottom, const UString &left, const UString &right)
void | SetHeader (const UString &header)
void | SetFooter (const UString &footer)
void | SetImageDPI (int dpi)
void | SetImageQuality (int quality)
void | SetCookieJar (const UString &path)
void | AddCookie (const UString &name, const UString &value)
void | SetCustomHeader (const UString &name, const UString &value)
void | Destroy ()

## Static Public Member Functions
static bool | Convert (PDFDoc &doc, const UString &url)
static bool | Convert (PDFDoc &doc, const UString &url, const WebPageSettings &settings)
static void | SetModulePath (const UString &path)
static bool | IsModuleAvailable ()

## Detailed Description

'pdftron.PDF.HTML2PDF' is an optional PDFNet Add-On utility class that can be used to convert HTML web pages into PDF documents by using an external module (html2pdf).

The html2pdf modules can be downloaded from http: www.pdftron.com/pdfnet/downloads.html.

Users can convert HTML pages to PDF using the following operations:

- Simple one line static method to convert a single web page to PDF.
- Convert HTML pages from URL or string, plus optional table of contents, in user defined order.
- Optionally configure settings for proxy, images, java script, and more for each HTML page.
- Optionally configure the PDF output, including page size, margins, orientation, and more.
- Optionally add table of contents, including setting the depth and appearance.

The following code converts a single webpage to pdf

using namespace pdftron;
using namespace PDF;
PDFDoc pdfdoc;
if ( HTML2PDF::Convert(pdfdoc, "http://www.gutenberg.org/wiki/Main_Page") )
pdfdoc.Save(outputFile, SDF::SDFDoc::e_remove_unused, NULL);
pdftron::PDF::HTML2PDF::Convert
static bool Convert(PDFDoc &doc, const UString &url)
pdftron::PDF::PDFDoc
Definition PDFDoc.h:72
pdftron::PDF::PDFDoc::Save
void Save(const UString &path, UInt32 flags)
pdftron::SDF::SDFDoc::e_remove_unused
@ e_remove_unused
Definition SDFDoc.h:355
pdftron::PDF
Definition Action.h:15
pdftron
Definition BasicTypes.h:10

The following code demonstrates how to convert multiple web pages into one pdf, excluding the background, and with lowered image quality to save space.

using namespace pdftron;
using namespace PDF;
HTML2PDF converter;
converter.SetImageQuality(25);
HTML2PDF::WebPageSettings settings;
settings.SetPrintBackground(false);
converter.InsertFromURL("http://www.gutenberg.org/wiki/Main_Page", settings);
PDFDoc pdfdoc;
if ( converter.Convert(pdfdoc) )
pdfdoc.Save(outputFile, SDF::SDFDoc::e_remove_unused, NULL);
pdftron::PDF::HTML2PDF::InsertFromURL
void InsertFromURL(const UString &url)
pdftron::PDF::HTML2PDF::WebPageSettings
pdftron::PDF::WebPageSettings WebPageSettings
Definition HTML2PDF.h:68
pdftron::PDF::HTML2PDF::HTML2PDF
HTML2PDF()
pdftron::PDF::HTML2PDF::SetImageQuality
void SetImageQuality(int quality)
pdftron::PDF::WebPageSettings::SetPrintBackground
void SetPrintBackground(bool background)

Definition at line 64 of file HTML2PDF.h.

## Member Typedef Documentation

## ◆ Proxy

typedef pdftron::PDF::Proxy pdftron::PDF::HTML2PDF::Proxy

Definition at line 67 of file HTML2PDF.h.

## ◆ TOCSettings

typedef pdftron::PDF::TOCSettings pdftron::PDF::HTML2PDF::TOCSettings

Definition at line 69 of file HTML2PDF.h.

## ◆ WebPageSettings

typedef pdftron::PDF::WebPageSettings pdftron::PDF::HTML2PDF::WebPageSettings

Definition at line 68 of file HTML2PDF.h.

## Constructor & Destructor Documentation

## ◆ HTML2PDF()

pdftron::PDF::HTML2PDF::HTML2PDF | ( |  | ) |

Default constructor.

## ◆ ~HTML2PDF()

pdftron::PDF::HTML2PDF::~HTML2PDF | ( |  | ) |

Destructor.

## Member Function Documentation

## ◆ AddCookie()

void pdftron::PDF::HTML2PDF::AddCookie | ( | const UString & | name,
|  | const UString & | value )

Add cookie to the HTTP Headers when converting via a URL.

Parameters

  name | - the name of the cookie.
  value | - the value of the cookie.

## ◆ Convert() [1/3]

bool pdftron::PDF::HTML2PDF::Convert | ( | PDFDoc & | doc | ) |

Convert HTML documents and append the results to doc.

Precondition
  html2pdf module must be located in the working directory, or with the PDFNetC library.

Returns
  true if successful, otherwise false. Use GetHttpErrorCode for possible HTTP errors.

Parameters

  doc | - Target PDF to which converted HTML pages will be appended to.

Note
  Use InsertFromURL and InsertFromHtmlString to add HTML documents to be converted.

## ◆ Convert() [2/3]

bool pdftron::PDF::HTML2PDF::Convert | ( | PDFDoc & | doc,
|  | const UString & | url )
| static

Convert the HTML document at url and append the results to doc.

Precondition
  html2pdf module must be located in the working directory, or with the PDFNetC library.

Returns
  true if successful, otherwise false. Use GetHttpErrorCode for possible HTTP errors.

Parameters

  doc | - Target PDF to which converted HTML pages will be appended to.
  url | - HTML page, or relative path to local HTML page, that will be converted to PDF format.

Note
  If you wish to convert more than one web page you need to use an instance of HTML2PDF.

## ◆ Convert() [3/3]

bool pdftron::PDF::HTML2PDF::Convert | ( | PDFDoc & | doc,
|  | const UString & | url,
|  | const WebPageSettings & | settings )
| static

Convert the HTML document at url and append the results to doc.

Precondition
  html2pdf module must be located in the working directory, or with the PDFNetC library.

Returns
  true if successful, otherwise false. Use GetHttpErrorCode for possible HTTP errors.

Parameters

  doc | - Target PDF to which converted HTML pages will be appended to.
  url | - HTML page, or relative path to local HTML page, that will be converted to PDF format.
  settings | - Modify how the web page is loaded and converted.

Note
  If you wish to convert more than one web page you need to use an instance of HTML2PDF.

## ◆ Destroy()

void pdftron::PDF::HTML2PDF::Destroy | ( |  | ) |

Frees the native memory of the object.

## ◆ DumpOutline()

void pdftron::PDF::HTML2PDF::DumpOutline | ( | const UString & | xml_file | ) |

Save outline to a xml file.

Parameters

  xml_file | - Path of where xml data representing outline of produced PDF should be saved to.

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ GetHTTPErrorCode()

int pdftron::PDF::HTML2PDF::GetHTTPErrorCode | ( |  | ) | const

Return the largest HTTP error code encountered during conversion

Returns
  the largest HTTP code greater then or equal to 300 encountered during loading of any of the supplied objects, if no such error code is found 0 is returned.

Note
  This function will only return a useful result after Convert has been called.

## ◆ GetLog()

UString pdftron::PDF::HTML2PDF::GetLog | ( |  | ) | const

Get results of conversion, including errors and warnings, in human readable form.

Returns
  String containing results of conversion.

## ◆ InsertFromHtmlString() [1/2]

void pdftron::PDF::HTML2PDF::InsertFromHtmlString | ( | const UString & | html | ) |

Convert HTML encoded in string.

Parameters

  html | - String containing HTML code.

## ◆ InsertFromHtmlString() [2/2]

void pdftron::PDF::HTML2PDF::InsertFromHtmlString | ( | const UString & | html,
|  | const WebPageSettings & | settings )

Convert HTML encoded in string.

Parameters

  html | - String containing HTML code.
  settings | - How the HTML content described in html is loaded.

## ◆ InsertFromURL() [1/2]

void pdftron::PDF::HTML2PDF::InsertFromURL | ( | const UString & | url | ) |

Add a web page to be converted. A single URL typically results in many PDF pages.

Parameters

  url | - HTML page, or relative path to local HTML page

## ◆ InsertFromURL() [2/2]

void pdftron::PDF::HTML2PDF::InsertFromURL | ( | const UString & | url,
|  | const WebPageSettings & | settings )

Add a web page to be converted. A single URL typically results in many PDF pages.

Parameters

  url | - HTML page, or relative path to local HTML page
  settings | - How the web page should be loaded and converted

## ◆ InsertTOC() [1/2]

void pdftron::PDF::HTML2PDF::InsertTOC | ( |  | ) |

Add a table of contents to the produced PDF.

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ InsertTOC() [2/2]

void pdftron::PDF::HTML2PDF::InsertTOC | ( | const TOCSettings & | settings | ) |

Add a table of contents to the produced PDF.

Parameters

  settings | - Settings for the table of contents.

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ IsModuleAvailable()

bool pdftron::PDF::HTML2PDF::IsModuleAvailable | ( |  | ) |
| static

Find out whether the HTLML2PDF module is available (and licensed).

Returns
  returns true if HTLML2PDF operations can be performed.

## ◆ SetCompatibilityMode()

void pdftron::PDF::HTML2PDF::SetCompatibilityMode | ( | bool | compatibility | ) |

Provides the ability to run HTML to PDF conversion to run in compatibility mode, which runs with altered graphics options and does not create a dedicated render process. This option may be somewhat slower than the default mode. However, it may be required on environments with limited platform dependencies, such as AWS Lambda.

Parameters

  compatibility | - If true, compatibility mode is enabled.

## ◆ SetCookieJar()

void pdftron::PDF::HTML2PDF::SetCookieJar | ( | const UString & | path | ) |

Path of file used for loading and storing cookies.

Parameters

  path | - Path to file used for loading and storing cookies.

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ SetCustomHeader()

void pdftron::PDF::HTML2PDF::SetCustomHeader | ( | const UString & | name,
|  | const UString & | value )

Add a custom HTTP header specified by name and value.

Parameters

  name | - the name of the custom header.
  value | - the value of the custom header.

## ◆ SetDPI()

void pdftron::PDF::HTML2PDF::SetDPI | ( | int | dpi | ) |

Change the DPI explicitly for the output PDF.

Parameters

  dpi | - Dots per inch, e.g. 80.

Attention
  This has no effect on X11 based systems.

Note
  Results also depend on SetSmartShrinking.

## ◆ SetFooter()

void pdftron::PDF::HTML2PDF::SetFooter | ( | const UString & | footer | ) |

Set footer of generated PDF.

Parameters

  footer | HTML string to be used as the footer

## ◆ SetHeader()

void pdftron::PDF::HTML2PDF::SetHeader | ( | const UString & | header | ) |

Set header of generated PDF.

Parameters

  header | HTML string to be used as the header

## ◆ SetImageDPI()

void pdftron::PDF::HTML2PDF::SetImageDPI | ( | int | dpi | ) |

Maximum DPI to use for images in the generated PDF.

Parameters

  dpi | - Maximum dpi of images in produced PDF, e.g. 80.

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ SetImageQuality()

void pdftron::PDF::HTML2PDF::SetImageQuality | ( | int | quality | ) |

JPEG compression factor to use when generating PDF.

Parameters

  quality | - Compression factor, e.g. 92.

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ SetLandscape()

void pdftron::PDF::HTML2PDF::SetLandscape | ( | bool | enable | ) |

Set page orientation for output PDF.

Parameters

  enable | - If true generated PDF pages will be orientated to landscape, otherwise orientation will be portrait.

## ◆ SetLogFilePath()

void pdftron::PDF::HTML2PDF::SetLogFilePath | ( | const UString & | path | ) |

Sets the location of the log file to be used during conversion.

Parameters

  path | Full path and filename of file to log to.

## ◆ SetMargins()

void pdftron::PDF::HTML2PDF::SetMargins | ( | const UString & | top,
|  | const UString & | bottom,
|  | const UString & | left,
|  | const UString & | right )

Set margins of generated PDF.

Parameters

  top | - Size of the top margin, e.g. "2cm".
  bottom | - Size of the bottom margin, e.g. "2cm".
  left | - Size of the left margin, e.g. "2cm".
  right | - Size of the right margin, e.g. "2cm".

Note
  Supported units are mm, cm, m, in, pc(pica), px(pixel) and pt(point).

## ◆ SetModulePath()

void pdftron::PDF::HTML2PDF::SetModulePath | ( | const UString & | path | ) |
| static

Set the only location that PDFNet will look for the html2pdf module.

Parameters

  path | - A folder or file path. If non-empty, PDFNet will only look in path for the html2pdf module, otherwise it will search in the default locations for the module.

## ◆ SetOutline()

void pdftron::PDF::HTML2PDF::SetOutline | ( | bool | enable,
|  | int | depth = 4 )

Add bookmarks to the PDF.

Parameters

  enable | - If true bookmarks will be generated for the produced PDF.
  depth | - Maximum depth of the outline (e.g. 4).

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ SetPaperSize() [1/2]

void pdftron::PDF::HTML2PDF::SetPaperSize | ( | const UString & | width,
|  | const UString & | height )

Manually set the paper dimensions of the produced PDF.

Parameters

  width | - Width of the page, e.g. "4cm".
  height | - Height of the page, eg. "12in".

Note
  Supported units are mm, cm, m, in, pc(pica), px(pixel) and pt(point).

## ◆ SetPaperSize() [2/2]

void pdftron::PDF::HTML2PDF::SetPaperSize | ( | PrinterMode::PaperSize | size | ) |

Set paper size of output PDF

Parameters

  size | - Paper size to use for produced PDF.

## ◆ SetPDFCompression()

void pdftron::PDF::HTML2PDF::SetPDFCompression | ( | bool | enable | ) |

Use loss less compression to create PDF.

Parameters

  enable | - If true loss less compression will be used to create PDF

Note
  This option is deprecated in the latest HTML2PDF module and may have no effect.

## ◆ SetQuiet()

void pdftron::PDF::HTML2PDF::SetQuiet | ( | bool | quiet | ) |

Display HTML to PDF conversion progress, warnings, and errors, to stdout.

Parameters

  quiet | - If false, progress information is sent to stdout during conversion.

Note
  You can get the final results using GetLog.

## ◆ SetSandbox()

void pdftron::PDF::HTML2PDF::SetSandbox | ( | bool | sandbox | ) |

Provides the ability to run HTML to PDF conversion with sandbox disabled. Default is true. Note: On Linux this option has no effect, because sandbox is always disabled there.

Parameters

  sandbox | - If false, '–no_sandbox' will be applied and the sandbox will not be used.

The documentation for this class was generated from the following file:

- PDF/HTML2PDF.h