Skip to main content
Version: 10.0

HTML Converter

The URLConverter and Converter web services can be used to convert HTML content into PDF format.

HTTP REST-APIOpenAPI
POST /urlconverter🔗
POST /converter/{documentId}🔗

Both of these web services use the Chromium-Bridge for this purpose. Therefore, the Chromium bridge must be activated to use HTML conversion.

"URLConverter" Web Service​

The URLConverter web service allows you to retrieve and convert HTML documents from a URL (with "http://" oder "https://" protocol). When using the web service, the HTML content of the URL is retrieved and then converted to a PDF document.

Important

By default, the URLConverter web service does not accept the file protocol (file://) in the URL; such a request is rejected with URLCONVERTER_INVALID_SOURCE_URL = -205.

For server security reasons and to avoid security vulnerabilities, access to local server resources is blocked via the file protocol. This is an important change since version 10.0.2 that may require adjustments to client applications. Access the resource via the http:// or https:// (recommended) protocol. Only if a deployment really needs local files, the setting WEBPDF_HTTP_OPTIONS_ALLOW_FILE_PROTOCOL=true allows the file protocol, see File Protocol Access.

The URLConverter is primarily intended for URLs over which you have control in terms of content and structure, e.g., your own websites or applications. While any URL can be converted with the web service, this will not always yield an optimal output quality, since these URLs are often optimized for screens, but not for PDFs.

If a URL is to be converted via this endpoint, then it is specified as the parameter url in the parameters of the web service.

{
"urlconverter": {
"url": "https://www.webpdf.de",
"page": {
"bottom": 20,
"height": 287,
"left": 20,
"metrics": "mm",
"right": 20,
"top": 20,
"width": 210
}
}
}

Comments:

  • All external contents (images, scripts, etc.) will always be retrieved
  • As of this writing, only the "Basic access authentication" authentication method is supported (please refer to URLConverter parameters)

Locale and time zone of the URLConverter​

With the optional locale and timeZone attributes of the urlconverter parameter, you set the language and the clock under which the page is retrieved and rendered. Both have the form described under locale and time zone.

{
"urlconverter": {
"url": "https://www.webpdf.de",
"locale": "en-US",
"timeZone": "America/New_York"
}
}
AttributeEffect
localeThe Accept-Language header with which the page and its resources are requested, so that the website can answer in that language; the locale seen by JavaScript in the page; the language and format of dates and numbers in the templates of the header and footer.
timeZoneThe time zone seen by JavaScript in the page, the date of a header or footer that uses the class date, and the time zone in which the templates of the header and footer show times.

If a request does not set an attribute, the default of the URLConverter web service applies, then the default of the server (see defaults of the server and of the web services). Without any of these, nothing changes compared to previous behavior: the page itself is requested without an Accept-Language header, and Chromium uses the settings of its process environment.

note

If the request sets an Accept-Language header itself in the HTTP settings (settings/http), that header takes precedence for the request of the page itself. The resources of the page are requested with the locale. JavaScript in frames that are loaded from another website does not see the locale or the time zone, and navigator.language keeps the language of the process environment of Chromium.

"Converter" web service​

The Converter web service processes HTML content that is available as a file or embedded in other formats, such as MSG or EML e-mail messages.

{
"converter": {
"jpegQuality": 100,
"mail": {
"adjustFonts": false,
"attachmentMode": "embed",
"downloadImages": false,
"ignoreMissingBodyChunk": false,
"reduceImageSize": false,
"resizeImages": false,
"resizeTables": false,
"useBackground": true
}
}
}

The downloadImages parameter can be used to specify whether externally referenced images should be downloaded when emails are converted. Only images with an absolute http or https address that names a host are requested; an address starting with // and a host (for example //example.com/image.png) is loaded via http. An image address without a host (for example /images/logo.png or logo.png), with another scheme, with a port above 65535, or with an unencoded @ in its user information is not requested. It is treated like an image that cannot be loaded (placeholder or alt text), and in the error report it is listed as an image that was not loaded, exactly as written in the document. The same applies to images referenced by CSS url() in an email. Credentials in an image address (https://user:password@example.com/image.png) apply to that one request only; they are not sent with other downloads of the same job.

The attachmentMode parameter specifies how the attachments of an e-mail are processed: embed (original format), remove, convert (convert to PDF and embed) or convertMerge (convert to PDF and append as additional pages). An attachment that cannot be converted stays embedded in its original format. If an attachment ends with a report error (-107, -108, -109) because of the report options, the e-mail ends with that error; see conversion reports.

Important Change

If the HTML content of an email contains links that are to be loaded using the file protocol (file://), these are blocked. For reasons of server security and to reduce potential attack vectors on the server, access to such resources has been blocked since version 10.0.2. The setting WEBPDF_HTTP_OPTIONS_ALLOW_FILE_PROTOCOL=true allows such resources, see File Protocol Access.

note

Conversion can be slowed down if downloadImages is enabled but the server does not have an external Internet connection. In this case, timeouts may slow down the conversion.

tip

When converting HTML documents, these should define a <base href=""> to be able to fully resolve links.