org.foray.pdf.object
Class PDFDocument

java.lang.Object
  extended by org.foray.pdf.object.PDFDocument
All Implemented Interfaces:
org.axsl.graphic.output.GraphicOutputContext, org.axsl.pdf.PdfDocument

public class PDFDocument
extends Object
implements org.axsl.pdf.PdfDocument, org.axsl.graphic.output.GraphicOutputContext

Represents a PDF document. The document is built up by calling various methods and then finally output to given filehandle using output method. A PDF document consists of a series of numbered objects preceded by a header and followed by an xref table and trailer. The xref table allows for quick access to objects by listing their character positions within the document. For this reason the PDF document must keep track of the character position of each object. The document also keeps direct track of the /Root, /Info and /Resources objects.


Field Summary
static int DEFAULT_CHARACTERS_PER_LINE
          The default line length of the output PDF document.
static String ENCODING
          Name of the CharSet that should be used when converting Strings to bytes.
 
Constructor Summary
PDFDocument(OutputStream outputStream, org.apache.commons.logging.Log logger, org.axsl.ps.PsServer psServer)
          Constructor which creates an empty PDF document.
 
Method Summary
 void addDefaultFilter(String filterToAdd)
           
 void addNamedDestination(String name, PDFDestination destination)
          Add a named destination to this document.
 void addPageLabelRange(int startingPageIndex, org.axsl.pdf.PdfPageLabelStyle labelStyle, CharSequence labelPrefix, int startingPageNumber)
           
 void close()
           
 PDFPattern createGradient(org.axsl.common.Gradient gradient)
           
 PDFColor createPdfColor(Color color)
           
 PDFEncryption createPdfEncryption()
           
 PDFPage createPdfPage(int pagewidth, int pageheight)
           
 PDFXObject findXObject(org.axsl.graphic.Graphic graphic)
          If a PDFXObject has already been created for a given URL, return that PDFXObject so that it can be reused.
 int getCharsPerLine()
          Return the number of characters per line that should be written into the PDF.
 ColorSpace getColorSpace()
          Returns the color space for this document.
 PDFBorderStyle getDefaultBorderStyle()
          Returns the default border style for this document.
 List<String> getDefaultFilters()
          Return the default list of filters to be applied to streams in this document.
 PDFEncryption getEncryption()
          Returns the encryption for this document, if any.
 String getFontName(org.axsl.font.FontUse fontUse)
           
 String getGradientName(org.axsl.common.Gradient gradient)
           
 PDFInfo getInfo()
          Get the /Info object for the document.
 org.apache.commons.logging.Log getLogger()
          Return the logger.
 String getNextFontSubsetTag()
          Computes the next available tag to be used as a prefix for a BaseFont or FontName entry, when the font is subsetted.
 PDFOutlineParent getOutlineRoot()
           
 PDFFont getPdfFont(org.axsl.font.output.FontPdf fontUse)
          Obtain a PDFFont for a given FontUse instance.
 org.axsl.ps.PsServer getPsServer()
          Returns the PostScript server.
 PDFResources getResources()
          Returns the /Resources object for the document.
 PDFRoot getRoot()
          Return the root object.
 PDFEncoding obtainPDFEncoding(org.axsl.ps.Encoding encoding)
          Obtain a PDFEncoding for a given Encoding instance.
 int registerFontResource(PDFFont font)
          Register a font resource for use in this document.
 void registerIndirectObject(PDFObject object)
          Register an object as an indirect object.
 void registerIndirectObjectLast(PDFObject object)
          Register an object as an indirect object that should be written at the end of the PDF output.
 int registerPatternResource(PDFPattern pattern)
          Register a pattern resource for use in this document.
 int registerShadingResource(PDFShading shading)
          Register a shading resource for use in this document.
 int registerXObjectResource(org.axsl.graphic.Graphic graphic, PDFXObject theXObject)
          Register an X object for use in this document.
 void setAuthor(String author)
          Sets the author of the document.
 void setColorSpace(ColorSpace theColorspace)
          Sets the color space for this document.
 void setCreationDate(Date creationDate)
           
 void setKeywords(String keywords)
          Sets the keywords of the document.
 void setProducer(String producer)
           
 void setSubject(String subject)
          Sets the subject of the document.
 void setTitle(String title)
          Sets the title of the document.
 void setVersion(org.axsl.pdf.PdfVersion newVersion)
           If not set, the default value is PDF_VERSION_1_6.
 void writeHeader()
           
 void writeIndirectObjects()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING

public static final String ENCODING
Name of the CharSet that should be used when converting Strings to bytes.

See Also:
Constant Field Values

DEFAULT_CHARACTERS_PER_LINE

public static final int DEFAULT_CHARACTERS_PER_LINE
The default line length of the output PDF document.

See Also:
Constant Field Values
Constructor Detail

PDFDocument

public PDFDocument(OutputStream outputStream,
                   org.apache.commons.logging.Log logger,
                   org.axsl.ps.PsServer psServer)
Constructor which creates an empty PDF document. The constructor creates a /Root and /Pages object to track the document but does not write these objects until the trailer is written. Note that the object ID of the pages object is determined now, and the xref table is updated later. This allows Pages to refer to their Parent before we write it out.

Parameters:
outputStream - The output stream to which this document should be written.
logger - The logger to which user messages should be written.
psServer - The PostScript server.
Method Detail

setVersion

public void setVersion(org.axsl.pdf.PdfVersion newVersion)
If not set, the default value is PDF_VERSION_1_6.

Specified by:
setVersion in interface org.axsl.pdf.PdfDocument

getEncryption

public PDFEncryption getEncryption()
Returns the encryption for this document, if any.

Returns:
The encryption for this document, or null if there is none.

getColorSpace

public ColorSpace getColorSpace()
Returns the color space for this document.

Returns:
The color space for this document.

setColorSpace

public void setColorSpace(ColorSpace theColorspace)
Sets the color space for this document.

Parameters:
theColorspace - The new color space.

getOutlineRoot

public PDFOutlineParent getOutlineRoot()
Specified by:
getOutlineRoot in interface org.axsl.pdf.PdfDocument

getResources

public PDFResources getResources()
Returns the /Resources object for the document.

Returns:
The /Resources object.

getInfo

public PDFInfo getInfo()
Get the /Info object for the document.

Returns:
the /Info object

writeIndirectObjects

public void writeIndirectObjects()
                          throws org.axsl.pdf.PdfException
Specified by:
writeIndirectObjects in interface org.axsl.pdf.PdfDocument
Throws:
org.axsl.pdf.PdfException

writeHeader

public void writeHeader()
                 throws org.axsl.pdf.PdfException
Specified by:
writeHeader in interface org.axsl.pdf.PdfDocument
Throws:
org.axsl.pdf.PdfException

close

public void close()
           throws org.axsl.pdf.PdfException
Specified by:
close in interface org.axsl.pdf.PdfDocument
Throws:
org.axsl.pdf.PdfException

registerIndirectObject

public void registerIndirectObject(PDFObject object)
Register an object as an indirect object.

Parameters:
object - The object to be registered as an indirect object.

registerIndirectObjectLast

public void registerIndirectObjectLast(PDFObject object)
Register an object as an indirect object that should be written at the end of the PDF output.

Parameters:
object - The object to be registered.

registerShadingResource

public int registerShadingResource(PDFShading shading)
Register a shading resource for use in this document.

Parameters:
shading - The shading resource to register.
Returns:
The incremented shading count.

registerPatternResource

public int registerPatternResource(PDFPattern pattern)
Register a pattern resource for use in this document.

Parameters:
pattern - The pattern resource to register.
Returns:
The incremented pattern count.

registerFontResource

public int registerFontResource(PDFFont font)
Register a font resource for use in this document.

Parameters:
font - The font resource to register.
Returns:
The incremented font count.

registerXObjectResource

public int registerXObjectResource(org.axsl.graphic.Graphic graphic,
                                   PDFXObject theXObject)
Register an X object for use in this document.

Parameters:
graphic - The Graphic instance backing the X object resource.
theXObject - The X object to register.
Returns:
The incremented X object count.

getRoot

public PDFRoot getRoot()
Return the root object.

Returns:
The root object.

getDefaultFilters

public List<String> getDefaultFilters()
Return the default list of filters to be applied to streams in this document.

Returns:
The default filters.

addDefaultFilter

public void addDefaultFilter(String filterToAdd)
Specified by:
addDefaultFilter in interface org.axsl.pdf.PdfDocument

getNextFontSubsetTag

public String getNextFontSubsetTag()
Computes the next available tag to be used as a prefix for a BaseFont or FontName entry, when the font is subsetted. The specification for the tag is described in PDF Reference, Second Edition, Section 5.5.3.

Returns:
The tag to be prefixed to the subset font's name.

getLogger

public org.apache.commons.logging.Log getLogger()
Return the logger.

Returns:
The logger.

getDefaultBorderStyle

public PDFBorderStyle getDefaultBorderStyle()
Returns the default border style for this document.

Returns:
Returns the default border style.

findXObject

public PDFXObject findXObject(org.axsl.graphic.Graphic graphic)
If a PDFXObject has already been created for a given URL, return that PDFXObject so that it can be reused.

Parameters:
graphic - The Graphic instance for which a PDFXObject is sought.
Returns:
The corresponding PDFXObject, or null if there is none.

obtainPDFEncoding

public PDFEncoding obtainPDFEncoding(org.axsl.ps.Encoding encoding)
Obtain a PDFEncoding for a given Encoding instance. This method ensures that unnecessary duplicate PDFEncoding instances are not created.

Parameters:
encoding - The encoding for which a PDFEncoding is needed.
Returns:
The appropriate PDFEncoding instance.

getPdfFont

public PDFFont getPdfFont(org.axsl.font.output.FontPdf fontUse)
Obtain a PDFFont for a given FontUse instance. This method ensures that unnecessary duplicate PDFFont instances are not created.

Specified by:
getPdfFont in interface org.axsl.pdf.PdfDocument
Parameters:
fontUse - The font for which a PDFFont is needed.
Returns:
The appropriate PDFFont instance.

setTitle

public void setTitle(String title)
Sets the title of the document.

Specified by:
setTitle in interface org.axsl.pdf.PdfDocument
Parameters:
title - The new title for the document.

setAuthor

public void setAuthor(String author)
Sets the author of the document.

Specified by:
setAuthor in interface org.axsl.pdf.PdfDocument
Parameters:
author - The new author of the document.

setSubject

public void setSubject(String subject)
Sets the subject of the document.

Specified by:
setSubject in interface org.axsl.pdf.PdfDocument
Parameters:
subject - The new subject of the document.

setKeywords

public void setKeywords(String keywords)
Sets the keywords of the document.

Specified by:
setKeywords in interface org.axsl.pdf.PdfDocument
Parameters:
keywords - The new keywords of the document.

setProducer

public void setProducer(String producer)
Specified by:
setProducer in interface org.axsl.pdf.PdfDocument

setCreationDate

public void setCreationDate(Date creationDate)
Specified by:
setCreationDate in interface org.axsl.pdf.PdfDocument

addNamedDestination

public void addNamedDestination(String name,
                                PDFDestination destination)
                         throws org.axsl.pdf.PdfException
Add a named destination to this document.

Parameters:
name - The name to which destination should be mapped.
destination - The destination to be mapped to name.
Throws:
org.axsl.pdf.PdfException - If name has already been registered in this document.

createPdfEncryption

public PDFEncryption createPdfEncryption()
Specified by:
createPdfEncryption in interface org.axsl.pdf.PdfDocument

createPdfColor

public PDFColor createPdfColor(Color color)
Specified by:
createPdfColor in interface org.axsl.pdf.PdfDocument

createPdfPage

public PDFPage createPdfPage(int pagewidth,
                             int pageheight)
Specified by:
createPdfPage in interface org.axsl.pdf.PdfDocument

getCharsPerLine

public int getCharsPerLine()
Return the number of characters per line that should be written into the PDF.

Returns:
The number of characters per line that should be written into the PDF.

getFontName

public String getFontName(org.axsl.font.FontUse fontUse)
Specified by:
getFontName in interface org.axsl.graphic.output.GraphicOutputContext

getGradientName

public String getGradientName(org.axsl.common.Gradient gradient)
Specified by:
getGradientName in interface org.axsl.graphic.output.GraphicOutputContext

addPageLabelRange

public void addPageLabelRange(int startingPageIndex,
                              org.axsl.pdf.PdfPageLabelStyle labelStyle,
                              CharSequence labelPrefix,
                              int startingPageNumber)
Specified by:
addPageLabelRange in interface org.axsl.pdf.PdfDocument

createGradient

public PDFPattern createGradient(org.axsl.common.Gradient gradient)
Specified by:
createGradient in interface org.axsl.pdf.PdfDocument

getPsServer

public org.axsl.ps.PsServer getPsServer()
Returns the PostScript server.

Returns:
The PostScript server.


Copyright © 2017. All rights reserved.