Wt provides two classes for rendering to PDF:
The class WPdfImage is a paint device for rendering to PDF. It supports two main use-cases:
WPdfImage paint device is typically used in
conjunction with a WPainter, which provides a
high-level unified painting API.
The PDF is generated using
The Haru Free PDF Library. This class
is included in the library only if
libharu was found during the
build of the library.
The following example shows how to use a
WPdfImage directly in
Another common use-case is to paint the contents of a
WPaintedWidget, such as a chart, to a PDF :
When you want to embed a PDF image into a larger document, you need to use its constructor which passes an existing PDF document and page for it to paint on. This approach is used for example by the WPdfRenderer to render XHTML to multi-page PDF files.
Font information is embedded in the PDF. Fonts supported are native
PostScript fonts (Base-14) (only ASCII-7), or true type fonts
addFontCollection() for more information on how
fonts are located and matched to WFont descriptions.
The paint device has the following limitations:
WPainter::drawImage()) can only be included from local files, and only JPG or PNG images can be embedded.
The class WPdfRenderer implements an XHTML to PDF renderer. It can be used to create multipage reports, without the need for programming tedious lay outing using a low-level drawing API.
The rendering engine supports only a subset of XHTML. See the documentation of WTextRenderer for more information.
Although the rendering class itself can render to any
WPaintDevice (with font metrics), by far the most common
use-case is to render to a PDF document using
WPdfImage. Typically, you will want to adapt the pixel
resolution By default it uses a pixel resolution of 72 DPI,
which is a common default for printed documents, but differs
from the default used by most browsers (which is 96 DPI and has
nothing to do with the actual screen resolution). The resolution
can be changed using
setDpi() and has the effect of
scaling down (or up) the rendering. This can be used in
setFontScale() to scale the font size
differently than other content.