Package org.openpdf.text.pdf
Class PdfWriter
java.lang.Object
org.openpdf.text.DocWriter
org.openpdf.text.pdf.PdfWriter
- All Implemented Interfaces:
AutoCloseable,EventListener,DocListener,ElementListener,PdfRunDirection,PdfVersion
A
DocWriter class for PDF.
When this PdfWriter is added to a certain PdfDocument, the PDF representation of every
Element added to this Document will be written to the outputstream.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class generates the structure of a PDF document. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PdfWriter.PdfBodybody of the PDF documentprotected intThe color number counter for the colors in the document.protected intThe compression level of the content streams.protected intThe current page number.protected PdfDictionaryprotected PdfContentByteThe direct content in this document.protected PdfContentByteThe direct content under in this document.protected HashMap<PdfDictionary, PdfObject[]> The patterns of this documentprotected LinkedHashMap<BaseFont, org.openpdf.text.pdf.FontDetails> The fonts of this documentprotected PdfDictionaryHolds value of property extraCatalog this is used for Output Intents.protected intThe font number counter for the fonts in the document.protected LinkedHashMap<PdfIndirectReference, Object[]> The form XObjects in this document.protected intThe name counter for the form XObjects name.protected booleanHolds value of property fullCompression.static final intThe highest generation number possible.protected PdfDictionaryA group attributes dictionary specifying the attributes of the page's page group for use in the transparent imaging modelprotected PdfDictionaryDictionary, containing all the images of the PDF documentprotected HashMap<PdfStream, PdfIndirectReference> A HashSet with Stream objects containing JBIG2 Globalsprotected ArrayList<PdfIndirectReference> The PdfIndirectReference to the pages.protected PdfDocumentthe pdfdocument object.protected PdfVersionImpStores the version information for the header and the catalog.static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)protected intA number referring to the previous Cross-Reference Table.protected PdfPagesThe root of the page tree.protected PdfNameThe value of the Tabs entry in the page dictionary.protected floatstatic final Stringpossible PDF version (header)static final Stringpossible PDF version (header)static final Stringpossible PDF version (header)static final Stringpossible PDF version (header)static final Stringpossible PDF version (header)static final Stringpossible PDF version (header)static final StringPDF version 2.0.protected byte[]XMP Metadata for the document. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPdfWriter(PdfDocument document, OutputStream os) Constructs aPdfWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotation(PdfAnnotation annot) addDirectImageSimple(Image image) Use this method to adds an image to the document but not to the page resources.addDirectImageSimple(Image image, PdfIndirectReference fixedRef) Adds an image to the document but not to the page resources.protected voidUse this method to add a PDF object to the PDF body.Use this method to add a PDF object to the PDF body.addToBody(PdfObject object, PdfIndirectReference ref) Use this method to add a PDF object to the PDF body.voidclose()Signals that theDocumentwas closed and that no otherElementswill be added.protected PdfDictionarygetCatalog(PdfIndirectReference rootObj) intReturns the compression level used for streams written by this writer.Retrieves a reference to the current page of the document.Use this method to get the default colorspaces.Use this method to get the direct content for this document.Use this method to get the direct content under for this document.getInfo()Use this method to get the info dictionary if you want to change it directly (add keys and values to the info dictionary).static PdfWritergetInstance(Document document, OutputStream os) Use this method to get an instance of thePdfWriter.getPageReference(int page) Use this method to get a reference to a page existing or not.Use this to get anPdfIndirectReferencefor an object that will be created in the future.protected PdfIndirectReferencegetReferenceJBIG2Globals(byte[] content) Gets an indirect reference to a JBIG2 Globals stream.getTabs()Returns the value to be used for the Tabs entry in the page tree.floatUse this method to get the user unit.booleanUse this method to find out if 1.5 compression is on.booleanGets the transparency blending colorspace.voidopen()Signals that theDocumenthas been opened and thatElementscan be added.voidsetCompressionLevel(int compressionLevel) Sets the compression level to be used for streams written by this writer.voidsetFixedFileId(byte[] fileId) Makes the file identifier (/ID) of the trailer the given bytes (16 are used), instead of a random value, so that the same document gives the same file.Methods inherited from class org.openpdf.text.DocWriter
add, flush, getISOBytes, isPaused, newPage, setMargins, setPageSize
-
Field Details
-
GENERATION_MAX
public static final int GENERATION_MAXThe highest generation number possible.- Since:
- iText 2.1.6
- See Also:
-
VERSION_1_2
possible PDF version (header)- See Also:
-
VERSION_1_3
possible PDF version (header)- See Also:
-
VERSION_1_4
possible PDF version (header)- See Also:
-
VERSION_1_5
possible PDF version (header)- See Also:
-
VERSION_1_6
possible PDF version (header)- See Also:
-
VERSION_1_7
possible PDF version (header)- See Also:
-
VERSION_2_0
PDF version 2.0.- See Also:
-
PDF_VERSION_1_2
possible PDF version (catalog) -
PDF_VERSION_1_3
possible PDF version (catalog) -
PDF_VERSION_1_4
possible PDF version (catalog) -
PDF_VERSION_1_5
possible PDF version (catalog) -
PDF_VERSION_1_6
possible PDF version (catalog) -
PDF_VERSION_1_7
possible PDF version (catalog) -
PDF_VERSION_2_0
possible PDF version (catalog) -
pdf
the pdfdocument object. -
directContent
The direct content in this document. -
directContentUnder
The direct content under in this document. -
body
body of the PDF document -
extraCatalog
Holds value of property extraCatalog this is used for Output Intents. -
root
The root of the page tree. -
pageReferences
The PdfIndirectReference to the pages. -
currentPageNumber
protected int currentPageNumberThe current page number. -
tabs
The value of the Tabs entry in the page dictionary.- Since:
- 2.1.5
-
prevxref
protected int prevxrefA number referring to the previous Cross-Reference Table. -
pdf_version
Stores the version information for the header and the catalog. -
xmpMetadata
protected byte[] xmpMetadataXMP Metadata for the document. -
fullCompression
protected boolean fullCompressionHolds value of property fullCompression. -
compressionLevel
protected int compressionLevelThe compression level of the content streams.- Since:
- 2.1.3
-
documentFonts
The fonts of this document -
fontNumber
protected int fontNumberThe font number counter for the fonts in the document. -
formXObjects
The form XObjects in this document. The key is the xref and the value is Object[]{PdfName, template}. -
formXObjectsCounter
protected int formXObjectsCounterThe name counter for the form XObjects name. -
colorNumber
protected int colorNumberThe color number counter for the colors in the document. -
documentExtGState
The patterns of this document -
documentProperties
-
group
A group attributes dictionary specifying the attributes of the page's page group for use in the transparent imaging model -
userunit
protected float userunit -
defaultColorspace
-
imageDictionary
Dictionary, containing all the images of the PDF document -
JBIG2Globals
A HashSet with Stream objects containing JBIG2 Globals- Since:
- 2.1.5
-
-
Constructor Details
-
PdfWriter
Constructs aPdfWriter.Remark: a PdfWriter can only be constructed by calling the method
getInstance(Document document, OutputStream os).- Parameters:
document- ThePdfDocumentthat has to be writtenos- TheOutputStreamthe writer has to write to.
-
-
Method Details
-
setFixedFileId
public void setFixedFileId(byte[] fileId) Makes the file identifier (/ID) of the trailer the given bytes (16 are used), instead of a random value, so that the same document gives the same file.- Parameters:
fileId- the identifier, or null for a random one (the default)
-
getInstance
Use this method to get an instance of thePdfWriter.- Parameters:
document- TheDocumentthat has to be writtenos- TheOutputStreamthe writer has to write to.- Returns:
- a new
PdfWriter - Throws:
DocumentException- on error
-
getInfo
Use this method to get the info dictionary if you want to change it directly (add keys and values to the info dictionary).- Returns:
- the info dictionary
-
getDirectContent
Use this method to get the direct content for this document. There is only one direct content, multiple calls to this method will allways retrieve the same object.- Returns:
- the direct content
-
getDirectContentUnder
Use this method to get the direct content under for this document. There is only one direct content, multiple calls to this method will always retrieve the same object.- Returns:
- the direct content
-
addToBody
Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object- the PDF object to add- Returns:
- a PdfIndirectObject
- Throws:
IOException- thrown when an I/O operation fails
-
addToBody
Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object- the PDF object to addinObjStm- a boolean- Returns:
- a PdfIndirectObject
- Throws:
IOException- thrown when an I/O operation fails
-
addToBody
Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object- the object to addref- the IndirectReference of that object- Returns:
- a PdfIndirectObject
- Throws:
IOException- thrown when an I/O operation fails
-
getPdfIndirectReference
Use this to get anPdfIndirectReferencefor an object that will be created in the future. Use this method only if you know what you're doing!- Returns:
- the
PdfIndirectReference
-
getCatalog
-
getPageReference
Use this method to get a reference to a page existing or not. If the page does not exist yet the reference will be created in advance. If on closing the document, a page number greater than the total number of pages was requested, an exception is thrown.- Parameters:
page- the page number. The first page is 1- Returns:
- the reference to the page
-
getCurrentPage
Retrieves a reference to the current page of the document. The current page is typically the last page that was modified or accessed.- Returns:
- a
PdfIndirectReferenceobject pointing to the current page in the PDF document.
-
getTabs
Returns the value to be used for the Tabs entry in the page tree.- Returns:
- a PdfName of the value of the Tabs entry in the page dictionnary
- Since:
- 2.1.5
-
open
public void open()Signals that theDocumenthas been opened and thatElementscan be added.When this method is called, the PDF-document header is written to the outputstream.
- Specified by:
openin interfaceDocListener- Overrides:
openin classDocWriter- See Also:
-
close
public void close()Signals that theDocumentwas closed and that no otherElementswill be added.The pages-tree is built and written to the outputstream. A Catalog is constructed, as well as an Info-object, the reference table is composed and everything is written to the outputstream embedded in a Trailer.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDocListener- Overrides:
closein classDocWriter- See Also:
-
addAnnotation
-
isFullCompression
public boolean isFullCompression()Use this method to find out if 1.5 compression is on.- Returns:
- the 1.5 compression status
-
getCompressionLevel
public int getCompressionLevel()Returns the compression level used for streams written by this writer.- Returns:
- the compression level (0 = best speed, 9 = best compression, -1 is default)
- Since:
- 2.1.3
-
setCompressionLevel
public void setCompressionLevel(int compressionLevel) Sets the compression level to be used for streams written by this writer.- Parameters:
compressionLevel- a value between 0 (best speed) and 9 (best compression)- Since:
- 2.1.3
-
getUserunit
public float getUserunit()Use this method to get the user unit. A user unit is a value that defines the default user space unit. The minimum UserUnit is 1 (1 unit = 1/72 inch). The maximum UserUnit is 75,000. Note that this userunit only works starting with PDF1.6!- Returns:
- Returns the userunit.
-
getDefaultColorspace
Use this method to get the default colorspaces.- Returns:
- the default colorspaces
-
getReferenceJBIG2Globals
Gets an indirect reference to a JBIG2 Globals stream. Adds the stream if it hasn't already been added to the writer.- Parameters:
content- a byte array that may already been added to the writer inside a stream object.- Returns:
- the PdfIndirectReference
- Since:
- 2.1.5
-
isRgbTransparencyBlending
public boolean isRgbTransparencyBlending()Gets the transparency blending colorspace.- Returns:
trueif the transparency blending colorspace is RGB,falseif it is the default blending colorspace- Since:
- 2.1.0
-
addDirectImageSimple
Use this method to adds an image to the document but not to the page resources. It is used with templates andDocument.add(Image). Use this method only if you know what you're doing!- Parameters:
image- theImageto add- Returns:
- the name of the image added
- Throws:
PdfException- on errorDocumentException- on error
-
addDirectImageSimple
public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) throws DocumentException Adds an image to the document but not to the page resources. It is used with templates andDocument.add(Image). Use this method only if you know what you're doing!- Parameters:
image- theImageto addfixedRef- the reference to used. It may benull, aPdfIndirectReferenceor aPRIndirectReference.- Returns:
- the name of the image added
- Throws:
PdfException- on errorDocumentException- on error
-