Wt
4.11.1
|
An XHTML to PDF renderer. More...
#include <Wt/Render/WPdfRenderer.h>
Public Member Functions | |
WPdfRenderer (HPDF_Doc pdf, HPDF_Page page=nullptr) | |
Creates a new PDF renderer. More... | |
void | setMargin (double cm, WFlags< Side > sides=AllSides) |
Sets the page margins. More... | |
void | setDpi (int dpi) |
Sets the resolution. More... | |
void | addFontCollection (const std::string &directory, bool recursive=true) |
Adds a font collection. More... | |
void | setCurrentPage (HPDF_Page page) |
Sets the current page. | |
HPDF_Page | currentPage () const |
Returns the current page. More... | |
virtual double | pageWidth (int page) const override |
Returns the page width. More... | |
virtual double | pageHeight (int page) const override |
Returns the page height. More... | |
virtual double | margin (Side side) const override |
Returns the margin. More... | |
virtual WPaintDevice * | startPage (int page) override |
Returns a paint device to render a given page. More... | |
virtual void | endPage (WPaintDevice *device) override |
Stops painting on the given page. | |
virtual WPainter * | getPainter (WPaintDevice *device) override |
Returns a painter for the current page. | |
virtual HPDF_Page | createPage (int page) |
Creates a new page. More... | |
Public Member Functions inherited from Wt::Render::WTextRenderer | |
virtual | ~WTextRenderer () |
Destructor. | |
double | render (const WString &text, double y=0) |
Renders an XHTML fragment. More... | |
bool | setStyleSheetText (const WString &contents) |
Sets the contents of a cascading style sheet (CSS). More... | |
bool | useStyleSheet (const WString &filename) |
Appends an external cascading style sheet (CSS). More... | |
void | clearStyleSheet () |
Clears the used stylesheet. More... | |
WString | styleSheetText () const |
Returns the CSS in use. More... | |
std::string | getStyleSheetParseErrors () const |
Returns all parse error information of the last call to setStyleSheetText. More... | |
double | textWidth (int page) const |
Returns the page text width. More... | |
double | textHeight (int page) const |
Returns the page text height. More... | |
void | setFontScale (double scale) |
Sets the scaling factor used for font rendering. More... | |
double | fontScale () const |
Returns the font scaling factor. More... | |
virtual void | paintNode (WPainter &painter, const Node &node) |
Paints an XHTML node. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Wt::Render::WTextRenderer | |
WTextRenderer () | |
Constructor. | |
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 (using WPdfImage).
By default it uses a pixel resolution of 72 DPI, which is the default for a WPdfImage, but differs from the default used by most browsers (which is 96 DPI and has nothing to do with the actual screen resolution). The pixel resolution can be configured using setDpi(). Increasing the resolution 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:
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.
Wt::Render::WPdfRenderer::WPdfRenderer | ( | HPDF_Doc | pdf, |
HPDF_Page | page = nullptr |
||
) |
Creates a new PDF renderer.
The PDF renderer will render on the given pdf
(starting). If the page
is not 0
, then rendering will happen on this first page (and its page sizes will be taken into account).
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.
If Wt has been configured to use libpango
, then font matching and character selection is done by libpango, and calls to this method are ignored. See WPdfImage::addFontCollection() for more details.
If Wt was not configured to use libpango
, you will have to add the directories where Wt should look for fonts. You will also have to specify the required font in the HTML source, e.g.:
|
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 page set with setCurrentPage() page.
|
overridevirtual |
Returns the margin.
Returns the margin at given side (in pixel units).
Implements Wt::Render::WTextRenderer.
|
overridevirtual |
Returns the page height.
Returns the total page height (in pixel units), including vertical margins.
Implements Wt::Render::WTextRenderer.
|
overridevirtual |
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.
Sets the page margins.
This sets page margins, in cm
, for one or more sides
.
|
overridevirtual |
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.