PD4ML document images
PD4ML supports conversion to PDF of the following image formats: JPEG, GIF, PNG,
popular BMP species and fax-specific TIFF.
In most of the cases source HTML document needs no adjustments for correct
image processing. If for some reason images are missing in the resulting PDF,
the first diagnostic step is to enable debug info output and to inspect
application console or server's log.
PD4ML supports the following image references:
1. Relative path. Image is located in the same or a neighbor directory where
the main document is.
As a rule the referencing works with no problems.
But in a case you pass the source HTML to PD4ML as a string object (wrapped to a
there is no base directory to compute relative paths. Make sure you call a
pd4ml.render() method with an explicit URL base parameter.
2. Absolute path. Not recommended.
By default PD4ML interprets the reference as a local file system path (file:/images/logo.gif)
and it is not what expected. Usually an image reference like "/images/logo.gif"
assumes an image path starting from the web application root, not from the file
system root. But by default, PD4ML has no access to web path -> physical
path mapping info.
A quick hack is to change the path to a relative one or to extend the URL to a fully-specified one:
http://localhost/webappname/images/logo.gif (would only work if the server does not host multiple domains,
otherwise it must be a real server name instead of
A more sophisticated approach is to pass ServletContext instance to pd4ml.useServletContext() method or
HttpServletRequest/Response instances to pd4ml.useHttpRequest() and
to let PD4ML to try to resolve the web application paths.
Fully specified URL.
Potential problems can happen in web application scenarios, when the server, where PD4ML is, cannot resolve
URL server name to IP address or has no routing to the remote server.
Also PD4ML oficially does not support HTTPS protocol. In most of the cases HTTPS references to image work. There is a number of application servers
(i.e. Weblogic, WebSphere) implement their own SSL layer, not derived from the
standard JDK classes. In the case ClassCastExceptionon is thrown. A
possible workaround is PD4ML custom resource
4. data protocol makes possible to embed image bytes into HTML document
text. The "reference" starts with "data:image/gif;base64," prefix,
followed by base64-encoded image bytes.
Note: PD4ML ignores the MIME type image/gif there, as it detects actual image type by the image data.
5. Proprietary java protocol allows to extract image from Java application resources using
a variety of Java ClassLoaders.
PD4ML tries to load an image, referenced that way, in three attempts.
resource = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
resource = this.getClass().getClassLoader().getResource(resourcePath);
resource = callingClass.getClassLoader().getResource(resourcePath);