The class WPdfImage is a paint device for rendering
to PDF. It supports two main use-cases:
as any other paint device, it can be used to create a PDF
output of the painting (which could e.g. be a chart or your
own painted widget), or
it can be used to embed Wt-generated contents into a larger PDF
document, e.g. to generate a report
A 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
conjunction with WPainter.
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
(Unicode). See addFontCollection() for more information on how
fonts are located and matched to WFont descriptions.
The paint device has the following limitations:
Images (cf. WPainter::drawImage()) can only be included
from local files, and only JPG or PNG images can be embedded.
The class Render::WPdfRenderer implements a XHTML to
PDF renderer. It can be used to create mult-page reports,
without the need for programming tedious layouting using a
low-level drawing API.
The rendering engine supports only a subset of XHTML. See the
documentation of Render::WTextRenderer for more information.
Although the rendering class itself can render to any
WPaintDevice (with font-metris), 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
conjunction with setFontScale() to scale the font size
differently than other content.