public class PdfDocument extends Document
PdfDocument
is the class that is used by PdfWriter
to translate a Document
into a PDF with different pages.
A PdfDocument
always listens to a Document
and adds the Pdf representation of every Element
that is
added to the Document
.
Document
,
DocListener
,
PdfWriter
Modifier and Type | Class and Description |
---|---|
static class |
PdfDocument.Indentation |
static class |
PdfDocument.PdfInfo
PdfInfo is the PDF InfoDictionary. |
protected static class |
PdfDocument.RenderingContext
This is a helper class for adding a Table to a document.
|
Modifier and Type | Field and Description |
---|---|
protected PdfDictionary |
additionalActions |
protected int |
alignment
This represents the current alignment of the PDF Elements.
|
protected PdfAction |
anchorAction
The current active
PdfAction when processing an Anchor . |
protected HashMap<String,PdfRectangle> |
boxSize
This is the size of the several boxes that will be used in
the next page.
|
protected PdfCollection |
collection |
protected float |
currentHeight
This is the current height of the document.
|
protected PdfOutline |
currentOutline
This is the current
PdfOutline in the hierarchy of outlines. |
protected HashMap<String,PdfIndirectReference> |
documentFileAttachment |
protected HashMap<String,PdfIndirectReference> |
documentLevelJS |
protected int |
duration
The duration of the page
|
protected boolean |
firstPageEvent
Signals that OnOpenDocument should be called.
|
protected PdfContentByte |
graphics
This is the PdfContentByte object, containing the borders and other Graphics.
|
protected float |
imageEnd
This is the position where the image ends.
|
protected Image |
imageWait
This is the image that could not be shown on a previous page.
|
protected PdfDocument.Indentation |
indentation |
protected PdfDocument.PdfInfo |
info
some meta information about the Document.
|
protected boolean |
isSectionTitle
Signals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).
|
protected int |
lastElementType
Holds the type of the last element, that has been added to the document.
|
protected float |
leading
This represents the leading of the lines.
|
protected int |
leadingCount
Signals that the current leading has to be subtracted from a YMark object when positive.
|
protected PdfLine |
line
The line that is currently being written.
|
protected List<PdfLine> |
lines
The lines that are written until now.
|
protected TreeMap<String,Object[]> |
localDestinations
Stores the destinations keyed by name.
|
protected int |
markPoint |
protected float |
nextMarginBottom
margin in y direction starting from the bottom.
|
protected float |
nextMarginLeft
margin in x direction starting from the left.
|
protected float |
nextMarginRight
margin in x direction starting from the right.
|
protected float |
nextMarginTop
margin in y direction starting from the top.
|
protected Rectangle |
nextPageSize
This is the size of the next page.
|
protected PdfAction |
openActionAction |
protected String |
openActionName |
protected PdfDictionary |
pageAA |
protected PdfPageLabels |
pageLabels |
protected com.lowagie.text.pdf.PageResources |
pageResources
This are the page resources of the current Page.
|
protected PdfOutline |
rootOutline
This is the root outline of the document.
|
protected static DecimalFormat |
SIXTEEN_DIGITS |
protected boolean |
strictImageSequence
Holds value of property strictImageSequence.
|
protected PdfContentByte |
text
This is the PdfContentByte object, containing the text.
|
protected int |
textEmptySize |
protected HashMap<String,PdfRectangle> |
thisBoxSize
This is the size of the several boxes of the current Page.
|
protected PdfIndirectReference |
thumb |
protected PdfTransition |
transition
The page transition
|
protected PdfViewerPreferencesImp |
viewerPreferences
Contains the Viewer preferences of this PDF document.
|
protected PdfWriter |
writer
The
PdfWriter . |
protected byte[] |
xmpMetadata
XMP Metadata for the page.
|
chapternumber, close, compress, footer, header, htmlStyleClass, javaScript_onLoad, javaScript_onUnLoad, marginBottom, marginLeft, marginMirroring, marginMirroringTopBottom, marginRight, marginTop, open, pageN, pageSize, plainRandomAccess, wmfFontCorrection
Constructor and Description |
---|
PdfDocument()
Constructs a new PDF document.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Element element)
Signals that an
Element was added to the Document . |
protected void |
add(Image image)
Adds an image to the document.
|
protected void |
addSpacing(float extraspace,
float oldleading,
Font f)
Adds extra space.
|
void |
addWriter(PdfWriter writer)
Adds a
PdfWriter to the PdfDocument . |
protected void |
analyzeRow(List<List<PdfCell>> rows,
PdfDocument.RenderingContext ctx) |
protected void |
carriageReturn()
If the current line is not empty or null, it is added to the arraylist
of lines and a new empty line is added.
|
void |
clearTextWrap()
Method added by Pelikan Stephan
|
void |
close()
Closes the document.
|
protected void |
consumeRowspan(List<PdfCell> row,
PdfDocument.RenderingContext ctx) |
protected void |
doFooter() |
protected void |
doHeader() |
protected void |
ensureNewLine()
Ensures that a new line has been started.
|
protected List<List<PdfCell>> |
extractRows(List<PdfCell> cells,
PdfDocument.RenderingContext ctx) |
protected float |
flushLines()
Writes all the lines to the text-object.
|
protected PdfDocument.PdfInfo |
getInfo()
Gets the
PdfInfo -object. |
float |
getLeading()
Getter for the current leading.
|
PdfOutline |
getRootOutline()
Gets the root outline.
|
float |
getVerticalPosition(boolean ensureNewLine)
Gets the current vertical page position.
|
protected float |
indentLeft()
Gets the indentation on the left side.
|
protected float |
indentRight()
Gets the indentation on the right side.
|
protected float |
indentTop()
Gets the indentation on the top side.
|
protected void |
initPage()
Initializes a page.
|
protected boolean |
mayBeRemoved(List<PdfCell> row) |
protected void |
newLine()
Adds the current line to the list of lines and also adds an empty line.
|
boolean |
newPage()
Makes a new page and sends it to the
PdfWriter . |
void |
open()
Opens the document.
|
protected void |
renderCells(PdfDocument.RenderingContext ctx,
List cells,
boolean hasToFit) |
void |
resetFooter()
Resets the footer of this document.
|
void |
resetHeader()
Resets the header of this document.
|
void |
resetPageCount()
Sets the page number to 0.
|
void |
setCollection(PdfCollection collection)
Sets the collection dictionary.
|
void |
setFooter(HeaderFooter footer)
Changes the footer of this document.
|
void |
setHeader(HeaderFooter header)
Changes the header of this document.
|
boolean |
setMarginMirroring(boolean MarginMirroring)
Set the margin mirroring.
|
boolean |
setMarginMirroringTopBottom(boolean MarginMirroringTopBottom)
Set the margin mirroring.
|
boolean |
setMargins(float marginLeft,
float marginRight,
float marginTop,
float marginBottom)
Sets the margins.
|
protected void |
setNewPageSizeAndMargins() |
void |
setPageCount(int pageN)
Sets the page number.
|
boolean |
setPageSize(Rectangle pageSize)
Sets the pagesize.
|
void |
setXmpMetadata(byte[] xmpMetadata)
Use this method to set the XMP Metadata.
|
addAuthor, addCreationDate, addCreator, addDocListener, addHeader, addKeywords, addProducer, addProducer, addSubject, addTitle, bottom, bottom, bottomMargin, getDocumentLanguage, getHtmlStyleClass, getJavaScript_onLoad, getJavaScript_onUnLoad, getPageNumber, getPageSize, getProduct, getRelease, getVersion, isMarginMirroring, isOpen, left, left, leftMargin, removeDocListener, right, right, rightMargin, setDocumentLanguage, setHtmlStyleClass, setJavaScript_onLoad, setJavaScript_onUnLoad, top, top, topMargin
protected PdfWriter writer
PdfWriter
.protected PdfContentByte text
protected PdfContentByte graphics
protected float leading
protected int alignment
protected float currentHeight
protected boolean isSectionTitle
protected int leadingCount
protected PdfAction anchorAction
PdfAction
when processing an Anchor
.protected int textEmptySize
protected byte[] xmpMetadata
protected float nextMarginLeft
protected float nextMarginRight
protected float nextMarginTop
protected float nextMarginBottom
protected boolean firstPageEvent
protected PdfLine line
protected int lastElementType
protected PdfDocument.Indentation indentation
protected PdfDocument.PdfInfo info
protected PdfOutline rootOutline
protected PdfOutline currentOutline
PdfOutline
in the hierarchy of outlines.protected PdfViewerPreferencesImp viewerPreferences
protected PdfPageLabels pageLabels
protected TreeMap<String,Object[]> localDestinations
Object[]{PdfAction,PdfIndirectReference,PdfDestintion}
.protected HashMap<String,PdfIndirectReference> documentLevelJS
protected static final DecimalFormat SIXTEEN_DIGITS
protected HashMap<String,PdfIndirectReference> documentFileAttachment
protected String openActionName
protected PdfAction openActionAction
protected PdfDictionary additionalActions
protected PdfCollection collection
protected int markPoint
protected Rectangle nextPageSize
protected HashMap<String,PdfRectangle> thisBoxSize
protected HashMap<String,PdfRectangle> boxSize
protected int duration
protected PdfTransition transition
protected PdfDictionary pageAA
protected PdfIndirectReference thumb
protected com.lowagie.text.pdf.PageResources pageResources
protected boolean strictImageSequence
protected float imageEnd
protected Image imageWait
public void addWriter(PdfWriter writer) throws DocumentException
PdfWriter
to the PdfDocument
.writer
- the PdfWriter
that writes everything
what is added to this document to an outputstream.DocumentException
- on errorpublic float getLeading()
public boolean add(Element element) throws DocumentException
Element
was added to the Document
.add
in interface ElementListener
add
in class Document
element
- the element to addtrue
if the element was added, false
if not.DocumentException
- when a document isn't open yet, or has been closedpublic void open()
You have to open the document before you can begin to add content to the body of the document.
open
in interface DocListener
open
in class Document
public void close()
Once all the content has been written in the body, you have to close the body. After that nothing can be written to the body anymore.
close
in interface DocListener
close
in interface AutoCloseable
close
in class Document
public void setXmpMetadata(byte[] xmpMetadata)
xmpMetadata
- The xmpMetadata to set.public boolean newPage()
PdfWriter
.newPage
in interface DocListener
newPage
in class Document
boolean
public boolean setPageSize(Rectangle pageSize)
setPageSize
in interface DocListener
setPageSize
in class Document
pageSize
- the new pagesizetrue
if the page size was setpublic boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
setMargins
in interface DocListener
setMargins
in class Document
marginLeft
- the margin on the leftmarginRight
- the margin on the rightmarginTop
- the margin on the topmarginBottom
- the margin on the bottomboolean
public boolean setMarginMirroring(boolean MarginMirroring)
Document
Note: it will not work with Table
.
setMarginMirroring
in interface DocListener
setMarginMirroring
in class Document
MarginMirroring
- true
to mirror the marginstrue
DocListener.setMarginMirroring(boolean)
public boolean setMarginMirroringTopBottom(boolean MarginMirroringTopBottom)
Document
Note: it will not work with Table
.
setMarginMirroringTopBottom
in interface DocListener
setMarginMirroringTopBottom
in class Document
MarginMirroringTopBottom
- true
to mirror the marginstrue
DocListener.setMarginMirroring(boolean)
public void setPageCount(int pageN)
setPageCount
in interface DocListener
setPageCount
in class Document
pageN
- the new page numberpublic void resetPageCount()
resetPageCount
in interface DocListener
resetPageCount
in class Document
public void setHeader(HeaderFooter header)
setHeader
in interface DocListener
setHeader
in class Document
header
- the new headerpublic void resetHeader()
resetHeader
in interface DocListener
resetHeader
in class Document
public void setFooter(HeaderFooter footer)
setFooter
in interface DocListener
setFooter
in class Document
footer
- the new footerpublic void resetFooter()
resetFooter
in interface DocListener
resetFooter
in class Document
protected void initPage() throws DocumentException
If the footer/header is set, it is printed.
DocumentException
- on errorprotected void newLine() throws DocumentException
DocumentException
- on errorprotected void carriageReturn()
public float getVerticalPosition(boolean ensureNewLine)
ensureNewLine
- Tells whether a new line shall be enforced. This may cause side effects
for elements that do not terminate the lines they've started because those lines will get
terminated.protected void ensureNewLine()
protected float flushLines() throws DocumentException
DocumentException
- on errorprotected float indentLeft()
protected float indentRight()
protected float indentTop()
protected void addSpacing(float extraspace, float oldleading, Font f)
extraspace
- extra spaceoldleading
- old leadingf
- fontprotected PdfDocument.PdfInfo getInfo()
PdfInfo
-object.PdfInfo
public PdfOutline getRootOutline()
public void setCollection(PdfCollection collection)
collection
- a dictionary of type PdfCollectionprotected void setNewPageSizeAndMargins()
public void clearTextWrap()
protected void add(Image image) throws DocumentException
image
- the Image
to addPdfException
- on errorDocumentException
- on errorprotected void analyzeRow(List<List<PdfCell>> rows, PdfDocument.RenderingContext ctx)
protected void consumeRowspan(List<PdfCell> row, PdfDocument.RenderingContext ctx)
protected List<List<PdfCell>> extractRows(List<PdfCell> cells, PdfDocument.RenderingContext ctx)
protected void renderCells(PdfDocument.RenderingContext ctx, List cells, boolean hasToFit) throws DocumentException
DocumentException
protected void doFooter() throws DocumentException
DocumentException
protected void doHeader() throws DocumentException
DocumentException
Copyright © 2020. All rights reserved.