Wt
3.2.1
|
An XHTML to PDF renderer. More...
#include <Wt/Render/WPdfRenderer>
Public Member Functions | |
WPdfRenderer (HPDF_Doc pdf, HPDF_Page page) | |
Creates a new PDF renderer. | |
void | setMargin (double cm, WFlags< Side > sides=All) |
Sets the page margins. | |
void | setDpi (int dpi) |
Sets the resolution. | |
void | addFontCollection (const std::string &directory, bool recursive=true) |
Adds a font collection. | |
HPDF_Page | currentPage () const |
Returns the current page. | |
virtual double | pageWidth (int page) const |
Returns the page width. | |
virtual double | pageHeight (int page) const |
Returns the page height. | |
virtual double | margin (Side side) const |
Returns the margin. | |
virtual WPaintDevice * | startPage (int page) |
Returns a paint device to render a given page. | |
virtual void | endPage (WPaintDevice *device) |
Stops painting on the given page. | |
virtual WPainter * | getPainter (WPaintDevice *device) |
Returns a painter for the current page. | |
virtual HPDF_Page | createPage (int page) |
Creates a new page. |
An XHTML to PDF renderer.
This class implements an XHTML to PDF renderer. The rendering engine supports only a subset of XHTML. See the documentation of WTextRenderer for more information.
The renderer renders to a libharu PDF document. By default it uses a pixel resolution of 72 DPI, which is the default for libharu, 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 increased using setDpi(). This has the effect of scaling down the rendering. This can be used in conjunction with setFontScale() to scale the font size differently than other content.
Usage example:
extern "C" { HPDF_STATUS HPDF_UseUTFEncodings(HPDF_Doc pdf); } HPDF_Doc pdf = HPDF_New(error_handler, 0); HPDF_UseUTFEncodings(pdf); // enables UTF-8 encoding with true type fonts HPDF_Page page = HPDF_AddPage(pdf); HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT); Render::WPdfRenderer renderer(pdf, page); renderer.setMargin(2.54); renderer.setDpi(96); renderer.render("<p style=\"background-color: #c11\">Hello, world !</p>"); HPDF_SaveToFile(pdf, "hello.pdf"); HPDF_Free(pdf);
Wt::Render::WPdfRenderer::WPdfRenderer | ( | HPDF_Doc | pdf, |
HPDF_Page | page | ||
) |
Creates a new PDF renderer.
The PDF renderer will render on the given pdf
(starting) on the given page
.
Default margins are 0, and the default DPI is 72.
void Wt::Render::WPdfRenderer::addFontCollection | ( | const std::string & | directory, |
bool | recursive = true |
||
) |
Adds a font collection.
HPDF_Page Wt::Render::WPdfRenderer::createPage | ( | int | page | ) | [virtual] |
Creates a new page.
The default implementation creates a new page with the same dimensions as the previous page.
You may want to specialize this method to add e.g.~headers and footers.
HPDF_Page Wt::Render::WPdfRenderer::currentPage | ( | ) | const |
Returns the current page.
This returns the page last created using createPage(), or the initial page if no additional apges have yet been created.
double Wt::Render::WPdfRenderer::margin | ( | Side | side | ) | const [virtual] |
Returns the margin.
Returns the margin at given side (in pixel units).
Implements Wt::Render::WTextRenderer.
double Wt::Render::WPdfRenderer::pageHeight | ( | int | page | ) | const [virtual] |
Returns the page height.
Returns the total page height (in pixel units), including vertical margins.
Implements Wt::Render::WTextRenderer.
double Wt::Render::WPdfRenderer::pageWidth | ( | int | page | ) | const [virtual] |
Returns the page width.
Returns the total page width (in pixel units), including horizontal margins.
Implements Wt::Render::WTextRenderer.
void Wt::Render::WPdfRenderer::setDpi | ( | int | dpi | ) |
Sets the resolution.
The resolution used between CSS pixels and actual page dimensions. Note that his does not have an effect on the de facto standard CSS resolution of 96 DPI that is used to convert between physical WLength units (like cm, inch and point) and pixels. Instead it has the effect of scaling down or up the rendered XHTML on the page.
The dpi setting also affects the pageWidth(), pageHeight(), and margin() pixel calculations.
The default resolution is 72 DPI (this is the default resolution used by libharu).
Sets the page margins.
This sets page margins, in cm
, for one or more sides
.
WPaintDevice * Wt::Render::WPdfRenderer::startPage | ( | int | page | ) | [virtual] |
Returns a paint device to render a given page.
The render() method calls this function once for each page it wants to render.
Implements Wt::Render::WTextRenderer.