com.itextpdf.text.pdf
Class PdfDocument

java.lang.Object
  extended by com.itextpdf.text.Document
      extended by com.itextpdf.text.pdf.PdfDocument
All Implemented Interfaces:
DocListener, ElementListener, IAccessibleElement, EventListener

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.

Since:
2.0.8 (class was package-private before)
See Also:
Document, DocListener, PdfWriter

Nested Class Summary
 class PdfDocument.Destination
           
static class PdfDocument.Indentation
           
static class PdfDocument.PdfInfo
          PdfInfo is the PDF InfoDictionary.
 
Field Summary
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,PdfObject> documentFileAttachment
           
protected  HashMap<String,PdfObject> documentLevelJS
           
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  PdfString language
           
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  ArrayList<PdfLine> lines
          The lines that are written until now.
protected  TreeMap<String,PdfDocument.Destination> 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  boolean openMCDocument
           
protected  PdfDictionary pageAA
           
protected  PdfPageLabels pageLabels
           
protected  com.itextpdf.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  HashMap<UUID,PdfStructureElement> structElements
           
protected  TabSettings tabSettings
          The current tab settings.
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  PdfViewerPreferencesImp viewerPreferences
          Contains the Viewer preferences of this PDF document.
protected  PdfWriter writer
          The PdfWriter.
 
Fields inherited from class com.itextpdf.text.Document
accessibleAttributes, chapternumber, close, compress, htmlStyleClass, id, javaScript_onLoad, javaScript_onUnLoad, listeners, marginBottom, marginLeft, marginMirroring, marginMirroringTopBottom, marginRight, marginTop, open, pageN, pageSize, plainRandomAccess, role, wmfFontCorrection
 
Constructor Summary
PdfDocument()
          Constructs a new PDF document.
 
Method Summary
 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 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 ensureNewLine()
          Ensures that a new line has been started.
protected  float flushLines()
          Writes all the lines to the text-object.
 float getLeading()
          Getter for the current leading.
 PdfPageLabels getPageLabels()
           
 PdfOutline getRootOutline()
          Gets the root outline.
 TabSettings getTabSettings()
          Getter for the current tab stops.
 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  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.
 void resetPageCount()
          Sets the page number to 0.
 void setCollection(PdfCollection collection)
          Sets the collection dictionary.
 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 setTabSettings(TabSettings tabSettings)
          Setter for the current tab stops.
 void setXmpMetadata(byte[] xmpMetadata)
          Use this method to set the XMP Metadata.
 
Methods inherited from class com.itextpdf.text.Document
addAuthor, addCreationDate, addCreator, addDocListener, addHeader, addKeywords, addLanguage, addProducer, addSubject, addTitle, bottom, bottom, bottomMargin, getAccessibleAttribute, getAccessibleAttributes, getHtmlStyleClass, getId, getJavaScript_onLoad, getJavaScript_onUnLoad, getPageNumber, getPageSize, getRole, isMarginMirroring, isOpen, left, left, leftMargin, removeDocListener, right, right, rightMargin, setAccessibleAttribute, setHtmlStyleClass, setId, setJavaScript_onLoad, setJavaScript_onUnLoad, setRole, top, top, topMargin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected PdfWriter writer
The PdfWriter.


structElements

protected HashMap<UUID,PdfStructureElement> structElements

openMCDocument

protected boolean openMCDocument

text

protected PdfContentByte text
This is the PdfContentByte object, containing the text.


graphics

protected PdfContentByte graphics
This is the PdfContentByte object, containing the borders and other Graphics.


leading

protected float leading
This represents the leading of the lines.


alignment

protected int alignment
This represents the current alignment of the PDF Elements.


currentHeight

protected float currentHeight
This is the current height of the document.


isSectionTitle

protected boolean isSectionTitle
Signals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).

Since:
2.1.2

leadingCount

protected int leadingCount
Signals that the current leading has to be subtracted from a YMark object when positive.

Since:
2.1.2

anchorAction

protected PdfAction anchorAction
The current active PdfAction when processing an Anchor.


tabSettings

protected TabSettings tabSettings
The current tab settings.

Since:
5.4.0

textEmptySize

protected int textEmptySize

nextMarginLeft

protected float nextMarginLeft
margin in x direction starting from the left. Will be valid in the next page


nextMarginRight

protected float nextMarginRight
margin in x direction starting from the right. Will be valid in the next page


nextMarginTop

protected float nextMarginTop
margin in y direction starting from the top. Will be valid in the next page


nextMarginBottom

protected float nextMarginBottom
margin in y direction starting from the bottom. Will be valid in the next page


firstPageEvent

protected boolean firstPageEvent
Signals that OnOpenDocument should be called.


line

protected PdfLine line
The line that is currently being written.


lines

protected ArrayList<PdfLine> lines
The lines that are written until now.


lastElementType

protected int lastElementType
Holds the type of the last element, that has been added to the document.


indentation

protected PdfDocument.Indentation indentation

info

protected PdfDocument.PdfInfo info
some meta information about the Document.


rootOutline

protected PdfOutline rootOutline
This is the root outline of the document.


currentOutline

protected PdfOutline currentOutline
This is the current PdfOutline in the hierarchy of outlines.


viewerPreferences

protected PdfViewerPreferencesImp viewerPreferences
Contains the Viewer preferences of this PDF document.


pageLabels

protected PdfPageLabels pageLabels

localDestinations

protected TreeMap<String,PdfDocument.Destination> localDestinations
Stores the destinations keyed by name. Value is a Destination.


documentLevelJS

protected HashMap<String,PdfObject> documentLevelJS

SIXTEEN_DIGITS

protected static final DecimalFormat SIXTEEN_DIGITS

documentFileAttachment

protected HashMap<String,PdfObject> documentFileAttachment

openActionName

protected String openActionName

openActionAction

protected PdfAction openActionAction

additionalActions

protected PdfDictionary additionalActions

collection

protected PdfCollection collection

language

protected PdfString language

markPoint

protected int markPoint

nextPageSize

protected Rectangle nextPageSize
This is the size of the next page.


thisBoxSize

protected HashMap<String,PdfRectangle> thisBoxSize
This is the size of the several boxes of the current Page.


boxSize

protected HashMap<String,PdfRectangle> boxSize
This is the size of the several boxes that will be used in the next page.


pageAA

protected PdfDictionary pageAA

pageResources

protected com.itextpdf.text.pdf.PageResources pageResources
This are the page resources of the current Page.


strictImageSequence

protected boolean strictImageSequence
Holds value of property strictImageSequence.


imageEnd

protected float imageEnd
This is the position where the image ends.


imageWait

protected Image imageWait
This is the image that could not be shown on a previous page.

Constructor Detail

PdfDocument

public PdfDocument()
Constructs a new PDF document.

Method Detail

addWriter

public void addWriter(PdfWriter writer)
               throws DocumentException
Adds a PdfWriter to the PdfDocument.

Parameters:
writer - the PdfWriter that writes everything what is added to this document to an outputstream.
Throws:
DocumentException - on error

getLeading

public float getLeading()
Getter for the current leading.

Returns:
the current leading
Since:
2.1.2

getTabSettings

public TabSettings getTabSettings()
Getter for the current tab stops.

Since:
5.4.0

setTabSettings

public void setTabSettings(TabSettings tabSettings)
Setter for the current tab stops.

Parameters:
tabSettings - the current tab settings
Since:
5.4.0

add

public boolean add(Element element)
            throws DocumentException
Signals that an Element was added to the Document.

Specified by:
add in interface ElementListener
Overrides:
add in class Document
Parameters:
element - the element to add
Returns:
true if the element was added, false if not.
Throws:
DocumentException - when a document isn't open yet, or has been closed

open

public void open()
Opens the document.

You have to open the document before you can begin to add content to the body of the document.

Specified by:
open in interface DocListener
Overrides:
open in class Document

close

public void close()
Closes the document. 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.

Specified by:
close in interface DocListener
Overrides:
close in class Document

setXmpMetadata

public void setXmpMetadata(byte[] xmpMetadata)
                    throws IOException
Use this method to set the XMP Metadata.

Parameters:
xmpMetadata - The xmpMetadata to set.
Throws:
IOException

newPage

public boolean newPage()
Makes a new page and sends it to the PdfWriter.

Specified by:
newPage in interface DocListener
Overrides:
newPage in class Document
Returns:
a boolean

setPageSize

public boolean setPageSize(Rectangle pageSize)
Sets the pagesize.

Specified by:
setPageSize in interface DocListener
Overrides:
setPageSize in class Document
Parameters:
pageSize - the new pagesize
Returns:
true if the page size was set

setMargins

public boolean setMargins(float marginLeft,
                          float marginRight,
                          float marginTop,
                          float marginBottom)
Sets the margins.

Specified by:
setMargins in interface DocListener
Overrides:
setMargins in class Document
Parameters:
marginLeft - the margin on the left
marginRight - the margin on the right
marginTop - the margin on the top
marginBottom - the margin on the bottom
Returns:
a boolean

setMarginMirroring

public boolean setMarginMirroring(boolean MarginMirroring)
Description copied from class: Document
Set the margin mirroring. It will mirror right/left margins for odd/even pages.

Specified by:
setMarginMirroring in interface DocListener
Overrides:
setMarginMirroring in class Document
Parameters:
MarginMirroring - true to mirror the margins
Returns:
always true
See Also:
DocListener.setMarginMirroring(boolean)

setMarginMirroringTopBottom

public boolean setMarginMirroringTopBottom(boolean MarginMirroringTopBottom)
Description copied from class: Document
Set the margin mirroring. It will mirror top/bottom margins for odd/even pages.

Specified by:
setMarginMirroringTopBottom in interface DocListener
Overrides:
setMarginMirroringTopBottom in class Document
Parameters:
MarginMirroringTopBottom - true to mirror the margins
Returns:
always true
Since:
2.1.6
See Also:
DocListener.setMarginMirroring(boolean)

setPageCount

public void setPageCount(int pageN)
Sets the page number.

Specified by:
setPageCount in interface DocListener
Overrides:
setPageCount in class Document
Parameters:
pageN - the new page number

resetPageCount

public void resetPageCount()
Sets the page number to 0.

Specified by:
resetPageCount in interface DocListener
Overrides:
resetPageCount in class Document

initPage

protected void initPage()
                 throws DocumentException
Initializes a page.

If the footer/header is set, it is printed.

Throws:
DocumentException - on error

newLine

protected void newLine()
                throws DocumentException
Adds the current line to the list of lines and also adds an empty line.

Throws:
DocumentException - on error

carriageReturn

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.


getVerticalPosition

public float getVerticalPosition(boolean ensureNewLine)
Gets the current vertical page position.

Parameters:
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.
Returns:
The current vertical page position.

ensureNewLine

protected void ensureNewLine()
Ensures that a new line has been started.


flushLines

protected float flushLines()
                    throws DocumentException
Writes all the lines to the text-object.

Returns:
the displacement that was caused
Throws:
DocumentException - on error

indentLeft

protected float indentLeft()
Gets the indentation on the left side.

Returns:
a margin

indentRight

protected float indentRight()
Gets the indentation on the right side.

Returns:
a margin

indentTop

protected float indentTop()
Gets the indentation on the top side.

Returns:
a margin

addSpacing

protected void addSpacing(float extraspace,
                          float oldleading,
                          Font f)
Adds extra space. This method should probably be rewritten.


getRootOutline

public PdfOutline getRootOutline()
Gets the root outline. All the outlines must be created with a parent. The first level is created with this outline.

Returns:
the root outline

getPageLabels

public PdfPageLabels getPageLabels()

setCollection

public void setCollection(PdfCollection collection)
Sets the collection dictionary.

Parameters:
collection - a dictionary of type PdfCollection

setNewPageSizeAndMargins

protected void setNewPageSizeAndMargins()

clearTextWrap

public void clearTextWrap()
Method added by Pelikan Stephan


add

protected void add(Image image)
            throws PdfException,
                   DocumentException
Adds an image to the document.

Parameters:
image - the Image to add
Throws:
PdfException - on error
DocumentException - on error


Copyright © 2013. All Rights Reserved.