Class WPdfRenderer
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 PDFJet 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 WTextRenderer#setFontScale()
to scale the font size differently than other content.
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.render.WTextRenderer
WTextRenderer.Node
-
Constructor Summary
ConstructorsConstructorDescriptionWPdfRenderer
(com.pdfjet.PDF pdf) Creates a new PDF renderer.WPdfRenderer
(com.pdfjet.PDF pdf, com.pdfjet.Page page) Creates a new PDF renderer. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addFontCollection
(String directory) Adds a font collection.void
addFontCollection
(String directory, boolean recursive) Adds a font collection.com.pdfjet.Page
createPage
(int page) Creates a new page.void
endPage
(WPaintDevice device) Stops painting on the given page.com.pdfjet.Page
Returns the current page.double
Returns the margin.getPainter
(WPaintDevice device) Returns a painter for the current page.double
pageHeight
(int page) Returns the page height.double
pageWidth
(int page) Returns the page width.void
setCurrentPage
(com.pdfjet.Page page) Sets the current page.void
setDpi
(int dpi) Sets the resolution.final void
setMargin
(double margin) Sets the page margins.final void
Sets the page margins.void
Sets the page margins.startPage
(int page) Returns a paint device to render a given page.Methods inherited from class eu.webtoolkit.jwt.render.WTextRenderer
clearStyleSheet, getFontScale, getStyleSheetParseErrors, getStyleSheetText, paintNode, render, render, setFontScale, setStyleSheetText, textHeight, textWidth, useStyleSheet
-
Constructor Details
-
WPdfRenderer
public WPdfRenderer(com.pdfjet.PDF pdf, com.pdfjet.Page page) Creates a new PDF renderer.The PDF renderer will render on the given
pdf
(starting). If thepage
is notnull
, 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.
-
WPdfRenderer
public WPdfRenderer(com.pdfjet.PDF pdf) Creates a new PDF renderer.
-
-
Method Details
-
setMargin
Sets the page margins.This sets page margins, in
cm
, for one or moresides
. -
setMargin
Sets the page margins. -
setMargin
public final void setMargin(double margin) Sets the page margins. -
setDpi
public void 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()
, andgetMargin()
pixel calculations.The default resolution is 72 DPI.
-
addFontCollection
Adds a font collection.If JWt has been configured to use
libpango
, then font matching and character selection is done by libpango, and calls to this method are ignored. SeeWPdfImage#addFontCollection()
for more details.If JWt was not configured to use
libpango
, you will have to add the directories where JWt should look for fonts. You will also have to specify the required font in the HTML source, e.g.:WPdfRenderer renderer = new WPdfRenderer(pdf, page); // ... renderer.render("<p style=\"font-family: 'DejaVuSans', Arial\">élève, fenêtre, âme</p>");
-
addFontCollection
Adds a font collection. -
setCurrentPage
public void setCurrentPage(com.pdfjet.Page page) Sets the current page. -
getCurrentPage
public com.pdfjet.Page getCurrentPage()Returns the current page.This returns the page last created using
createPage()
, or the page set withsetCurrentPage()
page. -
pageWidth
public double pageWidth(int page) Description copied from class:WTextRenderer
Returns the page width.Returns the total page width (in pixel units), including horizontal margins.
- Specified by:
pageWidth
in classWTextRenderer
-
pageHeight
public double pageHeight(int page) Description copied from class:WTextRenderer
Returns the page height.Returns the total page height (in pixel units), including vertical margins.
- Specified by:
pageHeight
in classWTextRenderer
-
getMargin
Description copied from class:WTextRenderer
Returns the margin.Returns the margin at given side (in pixel units).
- Specified by:
getMargin
in classWTextRenderer
-
startPage
Description copied from class:WTextRenderer
Returns a paint device to render a given page.The
render()
method calls this function once for each page it wants to render.- Specified by:
startPage
in classWTextRenderer
-
endPage
Description copied from class:WTextRenderer
Stops painting on the given page.- Specified by:
endPage
in classWTextRenderer
-
getPainter
Description copied from class:WTextRenderer
Returns a painter for the current page.- Specified by:
getPainter
in classWTextRenderer
-
createPage
public com.pdfjet.Page createPage(int page) 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.
-