Package org.apache.fop.pdf
Class PDFFactory
java.lang.Object
org.apache.fop.pdf.PDFFactory
This class provides method to create and register PDF objects.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Resolution of the User Space coordinate system (72dpi). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreatePDFEncoding
(SingleByteEncoding encoding, String fontName) Creates a PDFEncoding instance from a CodePointMapping instance.final PDFDocument
Returns the parent PDFDocument associated with this factory.getExternalAction
(String target, boolean newWindow) Create/find and return the appropriate external PDFAction according to the targetgetGoToReference
(String pdfPageRef, float yoffset) Create or find a PDF GoTo with the given page reference string and Y offset, and return its PDF object referencegetPDFGoTo
(String pdfPageRef, Point2D position) Finds and returns a PDFGoTo to the given page and position.protected PDFDestination
getUniqueDestination
(PDFDestination newdest) Registers and returns newdest if it is unique.Make an annotation list objectmakeArray
(int[] values) Make an Array object (ex.makeDestination
(String idRef, Object goToRef) Make a named destination.Make a the head object of the name dictionary (the /Dests object).void
makeEncoding
(String encodingName) make a /Encoding objectmakeFont
(String fontname, String basefont, String encoding, FontMetrics metrics, FontDescriptor descriptor) Make a Type1 /Font object.makeFontFile
(FontDescriptor desc, String fontPrefix) Embeds a font.makeFunction
(List domain, List range, float[] cZero, float[] cOne, double interpolationExponentN) make a type Exponential interpolation function (for shading usually)makeGState
(Map settings, PDFGState current) make an ExtGState for extra graphics options This tries to find a GState that will setup the correct values for the current context.makeICCBasedColorSpace
(PDFResourceContext res, String explicitName, PDFICCStream iccStream) Makes a new ICCBased color space and registers it in the resource context.protected PDFInfo
make an /Info objectmakeLink
(Rectangle2D rect, String dest, boolean isNamedDestination) Make an internal link.makeLink
(Rectangle2D rect, String destination, int linkType, float yoffset) Make aPDFLink
objectmakeLink
(Rectangle2D rect, String page, String dest) Make an internal link.makeLink
(Rectangle2D rect, PDFAction pdfAction) Create a PDF link to an existing PDFAction objectmakeMetadata
(org.apache.xmlgraphics.xmp.Metadata meta, boolean readOnly) Make a Metadata object.Make a names dictionary (the /Names object).Make a name tree node.makeNavigator
(String id) makeOutline
(PDFOutline parent, String label, String destination, float yoffset, boolean showSubItems) Make an outline object and add it to the given outlinemakeOutline
(PDFOutline parent, String label, PDFAction pdfAction, boolean showSubItems) Make an outline object and add it to the given parentmakeOutline
(PDFOutline parent, String label, PDFReference actionRef, boolean showSubItems) Make an outline object and add it to the given parentMake a OutputIntent dictionary.makePage
(PDFResources resources, int pageWidth, int pageHeight) Make a /Page object.makePage
(PDFResources resources, int pageWidth, int pageHeight, int pageIndex) Make a /Page object.makePage
(PDFResources resources, int pageIndex, Rectangle2D mediaBox, Rectangle2D cropBox, Rectangle2D bleedBox, Rectangle2D trimBox) Make a /Page object.Make a names dictionary (the /PageLabels object).Make a /Pages object.makePattern
(PDFResourceContext res, int thePatternType, PDFResources theResources, int thePaintType, int theTilingType, List theBBox, double theXStep, double theYStep, List theMatrix, List theXUID, StringBuffer thePatternDataStream) Make a tiling patternCreate a PDFICCStreamMake a /Resources object.Make a /Catalog (Root) object.makeSeparationColorSpace
(PDFResourceContext res, org.apache.xmlgraphics.java2d.color.NamedColorSpace ncs) Create a new Separation color space.makeStream
(String type, boolean add) Make a stream objectregisterFunction
(PDFFunction function) Registers a function against the documentregisterPattern
(PDFResourceContext res, PDFPattern pattern) registerShading
(PDFResourceContext res, PDFShading shading) Registers a shading object against the document
-
Field Details
-
DEFAULT_PDF_RESOLUTION
public static final int DEFAULT_PDF_RESOLUTIONResolution of the User Space coordinate system (72dpi).- See Also:
-
-
Constructor Details
-
PDFFactory
Creates a new PDFFactory.- Parameters:
document
- the parent PDFDocument needed to register the generated objects
-
-
Method Details
-
getDocument
Returns the parent PDFDocument associated with this factory.- Returns:
- PDFDocument the parent PDFDocument
-
makeRoot
Make a /Catalog (Root) object. This object is written in the trailer.- Parameters:
pages
- the pages pdf object that the root points to- Returns:
- the new pdf root object for this document
-
makePages
Make a /Pages object. This object is written in the trailer.- Returns:
- a new PDF Pages object for adding pages to
-
makeResources
Make a /Resources object. This object is written in the trailer.- Returns:
- a new PDF resources object
-
makeInfo
make an /Info object- Parameters:
prod
- string indicating application producing the PDF- Returns:
- the created /Info object
-
makeMetadata
Make a Metadata object.- Parameters:
meta
- the DOM Document containing the XMP metadata.readOnly
- true if the metadata packet should be marked read-only- Returns:
- the newly created Metadata object
-
makeOutputIntent
Make a OutputIntent dictionary.- Returns:
- the newly created OutputIntent dictionary
-
makePage
public PDFPage makePage(PDFResources resources, int pageIndex, Rectangle2D mediaBox, Rectangle2D cropBox, Rectangle2D bleedBox, Rectangle2D trimBox) Make a /Page object. The page is assigned an object number immediately so references can already be made. The page must be added to the PDFDocument later using addObject().- Parameters:
resources
- resources object to usepageIndex
- index of the page (zero-based)mediaBox
- the MediaBox areacropBox
- the CropBox areableedBox
- the BleedBox areatrimBox
- the TrimBox area- Returns:
- the created /Page object
-
makePage
Make a /Page object. The page is assigned an object number immediately so references can already be made. The page must be added to the PDFDocument later using addObject().- Parameters:
resources
- resources object to usepageWidth
- width of the page in pointspageHeight
- height of the page in pointspageIndex
- index of the page (zero-based)- Returns:
- the created /Page object
-
makePage
Make a /Page object. The page is assigned an object number immediately so references can already be made. The page must be added to the PDFDocument later using addObject().- Parameters:
resources
- resources object to usepageWidth
- width of the page in pointspageHeight
- height of the page in points- Returns:
- the created /Page object
-
makeFunction
public PDFFunction makeFunction(List domain, List range, float[] cZero, float[] cOne, double interpolationExponentN) make a type Exponential interpolation function (for shading usually)- Parameters:
domain
- List objects of Double objects. This is the domain of the function. See page 264 of the PDF 1.3 Spec.range
- List of Doubles that is the Range of the function. See page 264 of the PDF 1.3 Spec.cZero
- This is a vector of Double objects which defines the function result when x=0. This attribute is optional. It's described on page 268 of the PDF 1.3 spec.cOne
- This is a vector of Double objects which defines the function result when x=1. This attribute is optional. It's described on page 268 of the PDF 1.3 spec.interpolationExponentN
- This is the inerpolation exponent. This attribute is required. PDF Spec page 268- Returns:
- the PDF function that was created
-
registerFunction
Registers a function against the document- Parameters:
function
- The function to register
-
registerShading
Registers a shading object against the document- Parameters:
res
- The PDF resource contextshading
- The shading object to be registered
-
makePattern
public PDFPattern makePattern(PDFResourceContext res, int thePatternType, PDFResources theResources, int thePaintType, int theTilingType, List theBBox, double theXStep, double theYStep, List theMatrix, List theXUID, StringBuffer thePatternDataStream) Make a tiling pattern- Parameters:
res
- the PDF resource context to add the shading, may be nullthePatternType
- the type of pattern, which is 1 for tiling.theResources
- the resources associated with this patternthePaintType
- 1 or 2, colored or uncolored.theTilingType
- 1, 2, or 3, constant spacing, no distortion, or faster tilingtheBBox
- List of Doubles: The pattern cell bounding boxtheXStep
- horizontal spacingtheYStep
- vertical spacingtheMatrix
- Optional List of Doubles transformation matrixtheXUID
- Optional vector of Integers that uniquely identify the patternthePatternDataStream
- The stream of pattern data to be tiled.- Returns:
- the PDF pattern that was created
-
registerPattern
-
getUniqueDestination
Registers and returns newdest if it is unique. Otherwise, returns the equal destination already present in the document.- Parameters:
newdest
- a new, as yet unregistered destination- Returns:
- newdest if unique, else the already registered instance
-
makeDestination
Make a named destination.- Parameters:
idRef
- ID Reference for this destination (the name of the destination)goToRef
- Object reference to the GoTo Action- Returns:
- the newly created destrination
-
makeNames
Make a names dictionary (the /Names object).- Returns:
- the new PDFNames object
-
makePageLabels
Make a names dictionary (the /PageLabels object).- Returns:
- the new PDFPageLabels object
-
makeDests
Make a the head object of the name dictionary (the /Dests object).- Parameters:
destinationList
- a list of PDFDestination instances- Returns:
- the new PDFDests object
-
makeNameTreeNode
Make a name tree node.- Returns:
- the new name tree node
-
makeLink
Create a PDF link to an existing PDFAction object- Parameters:
rect
- the hotspot position in absolute coordinatespdfAction
- the PDFAction that this link refers to- Returns:
- the new PDFLink object, or null if either rect or pdfAction is null
-
makeLink
Make an internal link.- Parameters:
rect
- the hotspot position in absolute coordinatespage
- the target page reference valuedest
- the position destination- Returns:
- the new PDF link object
-
makeLink
Make an internal link.- Parameters:
rect
- the hotspot position in absolute coordinatesdest
- the position destinationisNamedDestination
- set to true if dest param is a named destination- Returns:
- the new PDF link object
-
makeLink
Make aPDFLink
object- Parameters:
rect
- the clickable rectangledestination
- the destination filelinkType
- the link typeyoffset
- the yoffset on the page for an internal link- Returns:
- the PDFLink object created
-
getExternalAction
Create/find and return the appropriate external PDFAction according to the target- Parameters:
target
- The external target. This may be a PDF file name (optionally with internal page number or destination) or any type of URI.newWindow
- boolean indicating whether the target should be displayed in a new window- Returns:
- the PDFAction thus created or found
-
getGoToReference
Create or find a PDF GoTo with the given page reference string and Y offset, and return its PDF object reference- Parameters:
pdfPageRef
- the PDF page reference, e.g. "23 0 R"yoffset
- the distance from the bottom of the page in points- Returns:
- the GoTo's object reference
-
getPDFGoTo
Finds and returns a PDFGoTo to the given page and position. Creates the PDFGoTo if not found.- Parameters:
pdfPageRef
- the PDF page referenceposition
- the (X,Y) position in points- Returns:
- the new or existing PDFGoTo object
-
makeOutline
public PDFOutline makeOutline(PDFOutline parent, String label, PDFReference actionRef, boolean showSubItems) Make an outline object and add it to the given parent- Parameters:
parent
- the parent PDFOutline object (may be null)label
- the title for the new outline objectactionRef
- the action reference string to be placed after the /AshowSubItems
- whether to initially display child outline items- Returns:
- the new PDF outline object
-
makeOutline
public PDFOutline makeOutline(PDFOutline parent, String label, PDFAction pdfAction, boolean showSubItems) Make an outline object and add it to the given parent- Parameters:
parent
- the parent PDFOutline object (may be null)label
- the title for the new outline objectpdfAction
- the action that this outline item points to - must not be null!showSubItems
- whether to initially display child outline items- Returns:
- the new PDFOutline object, or null if pdfAction is null
-
makeOutline
public PDFOutline makeOutline(PDFOutline parent, String label, String destination, float yoffset, boolean showSubItems) Make an outline object and add it to the given outline- Parameters:
parent
- parent PDFOutline object which may be nulllabel
- the title for the new outline objectdestination
- the reference string for the action to go toyoffset
- the yoffset on the destination pageshowSubItems
- whether to initially display child outline items- Returns:
- the new PDF outline object
-
makeEncoding
make a /Encoding object- Parameters:
encodingName
- character encoding scheme name- Returns:
- the created /Encoding object
-
makeFont
public PDFFont makeFont(String fontname, String basefont, String encoding, FontMetrics metrics, FontDescriptor descriptor) Make a Type1 /Font object.- Parameters:
fontname
- internal name to use for this font (eg "F1")basefont
- name of the base font (eg "Helvetica")encoding
- character encoding scheme used by the fontmetrics
- additional information about the fontdescriptor
- additional information about the font- Returns:
- the created /Font object
-
createPDFEncoding
Creates a PDFEncoding instance from a CodePointMapping instance.- Parameters:
encoding
- the code point mapping (encoding)fontName
- ...- Returns:
- the PDF Encoding dictionary (or a String with the predefined encoding)
-
makeFontFile
Embeds a font.- Parameters:
desc
- FontDescriptor of the font.- Returns:
- PDFStream The embedded font file
-
makeStream
Make a stream object- Parameters:
type
- the type of stream to be createdadd
- if true then the stream will be added immediately- Returns:
- the stream object created
-
makePDFICCStream
Create a PDFICCStream- Returns:
- the new PDF ICC stream object
- See Also:
-
makeICCBasedColorSpace
public PDFICCBasedColorSpace makeICCBasedColorSpace(PDFResourceContext res, String explicitName, PDFICCStream iccStream) Makes a new ICCBased color space and registers it in the resource context.- Parameters:
res
- the PDF resource context to add the shading, may be nullexplicitName
- the explicit name for the color space, may be nulliccStream
- the ICC stream to associate with this color space- Returns:
- the newly instantiated color space
-
makeSeparationColorSpace
public PDFSeparationColorSpace makeSeparationColorSpace(PDFResourceContext res, org.apache.xmlgraphics.java2d.color.NamedColorSpace ncs) Create a new Separation color space.- Parameters:
res
- the resource context (may be null)ncs
- the named color space to map to a separation color space- Returns:
- the newly created Separation color space
-
makeArray
Make an Array object (ex. Widths array for a font).- Parameters:
values
- the int array values- Returns:
- the PDF Array with the int values
-
makeGState
make an ExtGState for extra graphics options This tries to find a GState that will setup the correct values for the current context. If there is no suitable GState it will create a new one.- Parameters:
settings
- the settings required by the callercurrent
- the current GState of the current PDF context- Returns:
- a PDF GState, either an existing GState or a new one
-
makeAnnotList
Make an annotation list object- Returns:
- the annotation list object created
-
makeLayer
-
makeSetOCGStateAction
-
makeTransitionAction
-
makeDPart
-
makeDPartRoot
-