public class Document extends Object implements RenderListener
| Modifier and Type | Field and Description |
|---|---|
static PageFormat |
DEFAULT_PAGE_FORMAT
A4 portrait without margins.
|
| Constructor and Description |
|---|
Document()
Creates a Document using the
DEFAULT_PAGE_FORMAT. |
Document(float marginLeft,
float marginRight,
float marginTop,
float marginBottom)
Creates a Document in A4 with orientation portrait and the given margins.
|
Document(PageFormat pageFormat)
Creates a Document based on the given page format.
|
Document(org.apache.pdfbox.pdmodel.common.PDRectangle mediaBox)
Deprecated.
use
Document(PageFormat) instead. |
Document(org.apache.pdfbox.pdmodel.common.PDRectangle mediaBox,
float marginLeft,
float marginRight,
float marginTop,
float marginBottom)
Deprecated.
use
Document(PageFormat) instead. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Element element)
Adds an element to the document using a
VerticalLayoutHint. |
void |
add(Element element,
LayoutHint layoutHint)
Adds an element with the given layout hint.
|
void |
addRenderer(Renderer renderer)
Adds a (custom)
Renderer that may handle the rendering of an
element. |
void |
addRenderListener(RenderListener listener)
Adds a
RenderListener that will be notified during
rendering. |
void |
afterPage(RenderContext renderContext)
Called after any rendering is performed to the page.
|
void |
beforePage(RenderContext renderContext)
Called before any rendering is performed to the page.
|
float |
getMarginBottom()
Deprecated.
use
getPageFormat() instead. |
float |
getMarginLeft()
Deprecated.
use
getPageFormat() instead. |
float |
getMarginRight()
Deprecated.
use
getPageFormat() instead. |
float |
getMarginTop()
Deprecated.
use
getPageFormat() instead. |
org.apache.pdfbox.pdmodel.common.PDRectangle |
getMediaBox()
Deprecated.
use
getPageFormat() instead. |
Orientation |
getOrientation()
Deprecated.
use
getPageFormat() instead. |
PageFormat |
getPageFormat() |
float |
getPageHeight() |
float |
getPageWidth() |
org.apache.pdfbox.pdmodel.PDDocument |
getPDDocument()
Returns the
PDDocument to be created by method render(). |
void |
remove(Element element)
Removes the given element.
|
void |
removeRenderer(Renderer renderer)
Removes a
Renderer . |
void |
removeRenderListener(RenderListener listener)
Removes a
RenderListener . |
org.apache.pdfbox.pdmodel.PDDocument |
render()
Renders all elements and returns the resulting
PDDocument. |
protected void |
resetPDDocument()
Called after
render() in order to release the current document. |
void |
save(File file)
Renders the document and saves it to the given file. |
void |
save(OutputStream output)
Renders the document and saves it to the given output
stream. |
public static final PageFormat DEFAULT_PAGE_FORMAT
public Document()
DEFAULT_PAGE_FORMAT.public Document(float marginLeft,
float marginRight,
float marginTop,
float marginBottom)
VerticalLayout is used.marginLeft - the left marginmarginRight - the right marginmarginTop - the top marginmarginBottom - the bottom margin@Deprecated public Document(org.apache.pdfbox.pdmodel.common.PDRectangle mediaBox)
Document(PageFormat) instead.VerticalLayout is used.mediaBox - the media box to use.@Deprecated public Document(org.apache.pdfbox.pdmodel.common.PDRectangle mediaBox, float marginLeft, float marginRight, float marginTop, float marginBottom)
Document(PageFormat) instead.VerticalLayout is used.mediaBox - the media box to use.marginLeft - the left marginmarginRight - the right marginmarginTop - the top marginmarginBottom - the bottom marginpublic Document(PageFormat pageFormat)
VerticalLayout is used.pageFormat - the page format box to use.public void add(Element element)
VerticalLayoutHint.element - the element to addpublic void add(Element element, LayoutHint layoutHint)
element - the element to addlayoutHint - the hint for the Layout.public void remove(Element element)
element - the element to remove.public PageFormat getPageFormat()
@Deprecated public float getMarginLeft()
getPageFormat() instead.@Deprecated public float getMarginRight()
getPageFormat() instead.@Deprecated public float getMarginTop()
getPageFormat() instead.@Deprecated public float getMarginBottom()
getPageFormat() instead.@Deprecated public org.apache.pdfbox.pdmodel.common.PDRectangle getMediaBox()
getPageFormat() instead.@Deprecated public Orientation getOrientation()
getPageFormat() instead.public float getPageWidth()
public float getPageHeight()
public org.apache.pdfbox.pdmodel.PDDocument getPDDocument()
PDDocument to be created by method render().
Beware that this PDDocument is released after rendering. This means each
rendering process creates a new PDDocument.render().protected void resetPDDocument()
render() in order to release the current document.public void addRenderer(Renderer renderer)
Renderer that may handle the rendering of an
element. All renderers will be asked to render the current element in the
order they have been added. If no renderer is capable, the default
renderer will be asked.renderer - the renderer to add.public void removeRenderer(Renderer renderer)
Renderer .renderer - the renderer to remove.public org.apache.pdfbox.pdmodel.PDDocument render()
throws IOException
PDDocument.PDDocumentIOException - by pdfboxpublic void save(File file) throws IOException
Renders the document and saves it to the given file.file - the file to save to.IOException - by pdfboxpublic void save(OutputStream output) throws IOException
Renders the document and saves it to the given output
stream.output - the stream to save to.IOException - by pdfboxpublic void addRenderListener(RenderListener listener)
RenderListener that will be notified during
rendering.listener - the listener to add.public void removeRenderListener(RenderListener listener)
RenderListener .listener - the listener to remove.public void beforePage(RenderContext renderContext) throws IOException
RenderListenerbeforePage in interface RenderListenerrenderContext - the context providing all rendering state.IOException - by pdfbox.public void afterPage(RenderContext renderContext) throws IOException
RenderListenerafterPage in interface RenderListenerrenderContext - the context providing all rendering state.IOException - by pdfbox.Copyright © 2022. All rights reserved.