org.apache.fop.pdf
Class PDFDocument
- public class PDFDocument
class representing 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.
Constructor Summary |
PDFDocument() creates an empty PDF document |
Method Summary |
int | addImage(FopImage img) |
PDFPattern | createGradient(boolean radial, ColorSpace theColorspace, Vector theColors, Vector theBounds, Vector theCoords) |
int | getColorSpace() |
PDFResources | getResources() get the /Resources object for the document |
PDFAnnotList | makeAnnotList() make an annotation list object |
PDFArray | makeArray(int[] values) make an Array object (ex. |
PDFEncoding | makeEncoding(String encodingName) make a /Encoding object |
PDFFont | makeFont(String fontname, String basefont, String encoding, FontMetric metrics, FontDescriptor descriptor) make a Type1 /Font object |
PDFFontDescriptor | makeFontDescriptor(FontDescriptor desc) make a /FontDescriptor object for a CID font |
PDFFunction | makeFunction(int theFunctionType, Vector theDomain, Vector theRange, Vector theSize, int theBitsPerSample, int theOrder, Vector theEncode, Vector theDecode, StringBuffer theFunctionDataStream, Vector theFilter) Make a Type 0 sampled function |
PDFFunction | makeFunction(int theFunctionType, Vector theDomain, Vector theRange, Vector theCZero, Vector theCOne, double theInterpolationExponentN) make a type Exponential interpolation function
(for shading usually) |
PDFFunction | makeFunction(int theFunctionType, Vector theDomain, Vector theRange, Vector theFunctions, Vector theBounds, Vector theEncode) Make a Type 3 Stitching function |
PDFFunction | makeFunction(int theNumber, int theFunctionType, Vector theDomain, Vector theRange, StringBuffer theFunctionDataStream) make a postscript calculator function |
PDFLink | makeLink(Rectangle rect, String destination, int linkType) make a link object |
PDFPage | makePage(PDFResources resources, PDFStream contents, int pagewidth, int pageheight, Page currentPage) make a /Page object |
PDFPattern | makePattern(int thePatternType, PDFResources theResources, int thePaintType, int theTilingType, Vector theBBox, double theXStep, double theYStep, Vector theMatrix, Vector theXUID, StringBuffer thePatternDataStream) Make a tiling pattern |
PDFPattern | makePattern(int thePatternType, PDFShading theShading, Vector theXUID, StringBuffer theExtGState, Vector theMatrix) Make a smooth shading pattern |
PDFShading | makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, Vector theDomain, Vector theMatrix, PDFFunction theFunction) make a function based shading object |
PDFShading | makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, Vector theCoords, Vector theDomain, PDFFunction theFunction, Vector theExtend) Make an axial or radial shading object. |
PDFShading | makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, int theBitsPerFlag, Vector theDecode, PDFFunction theFunction) Make a free-form gouraud shaded triangle mesh, coons patch mesh, or tensor patch mesh
shading object |
PDFShading | makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, Vector theDecode, int theVerticesPerRow, PDFFunction theFunction) make a Lattice-Form Gouraud mesh shading object |
PDFStream | makeStream() make a stream object |
void | output(OutputStream stream) write the entire document out |
void | setColorSpace(int theColorspace) |
void | setIDReferences(IDReferences idReferences) |
void | setProducer(String producer) set the producer of the document |
PDFDocument
public PDFDocument()
- creates an empty PDF document
addImage
public int addImage(FopImage img)
createGradient
public PDFPattern createGradient(boolean radial, ColorSpace theColorspace, Vector theColors, Vector theBounds, Vector theCoords)
getColorSpace
public int getColorSpace()
getResources
public PDFResources getResources()
- get the /Resources object for the document
- Returns: the /Resources object
makeAnnotList
public PDFAnnotList makeAnnotList()
- make an annotation list object
- Returns: the annotation list object created
makeArray
public PDFArray makeArray(int[] values)
- make an Array object (ex. Widths array for a font)
makeEncoding
public PDFEncoding makeEncoding(String encodingName)
- 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, FontMetric 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 font
- metrics - additional information about the font
- descriptor - additional information about the font
- Returns: the created /Font object
makeFontDescriptor
public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc)
- make a /FontDescriptor object for a CID font
makeFunction
public PDFFunction makeFunction(int theFunctionType, Vector theDomain, Vector theRange, Vector theSize, int theBitsPerSample, int theOrder, Vector theEncode, Vector theDecode, StringBuffer theFunctionDataStream, Vector theFilter)
- Make a Type 0 sampled function
- Parameters:
- theDomain - Vector objects of Double objects.
This is the domain of the function.
See page 264 of the PDF 1.3 Spec.
- theRange - Vector objects of Double objects.
This is the Range of the function.
See page 264 of the PDF 1.3 Spec.
- theSize - A Vector object of Integer objects.
This is the number of samples in each input dimension.
I can't imagine there being more or less than two input dimensions,
so maybe this should be an array of length 2.
See page 265 of the PDF 1.3 Spec.
- theBitsPerSample - An int specifying the number of bits user to represent each sample value.
Limited to 1,2,4,8,12,16,24 or 32.
See page 265 of the 1.3 PDF Spec.
- theOrder - The order of interpolation between samples. Default is 1 (one). Limited
to 1 (one) or 3, which means linear or cubic-spline interpolation.
This attribute is optional.
See page 265 in the PDF 1.3 spec.
- theEncode - Vector objects of Double objects.
This is the linear mapping of input values intop the domain
of the function's sample table. Default is hard to represent in
ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
This attribute is optional.
See page 265 in the PDF 1.3 spec.
- theDecode - Vector objects of Double objects.
This is a linear mapping of sample values into the range.
The default is just the range.
This attribute is optional.
Read about it on page 265 of the PDF 1.3 spec.
- theFunctionDataStream - The sample values that specify the function are provided in a stream.
This is optional, but is almost always used.
Page 265 of the PDF 1.3 spec has more.
- theFilter - This is a vector of String objects which are the various filters that
have are to be applied to the stream to make sense of it. Order matters,
so watch out.
This is not documented in the Function section of the PDF 1.3 spec,
it was deduced from samples that this is sometimes used, even if we may never
use it in FOP. It is added for completeness sake.
- theNumber - The object number of this PDF object.
- theFunctionType - This is the type of function (0,2,3, or 4).
It should be 0 as this is the constructor for sampled functions.
makeFunction
public PDFFunction makeFunction(int theFunctionType, Vector theDomain, Vector theRange, Vector theCZero, Vector theCOne, double theInterpolationExponentN)
- make a type Exponential interpolation function
(for shading usually)
- Parameters:
- theDomain - Vector objects of Double objects.
This is the domain of the function.
See page 264 of the PDF 1.3 Spec.
- theRange - Vector of Doubles that is the Range of the function.
See page 264 of the PDF 1.3 Spec.
- theCZero - 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.
- theCOne - 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.
- theInterpolationExponentN - This is the inerpolation exponent.
This attribute is required.
PDF Spec page 268
- theFunctionType - The type of the function, which should be 2.
makeFunction
public PDFFunction makeFunction(int theFunctionType, Vector theDomain, Vector theRange, Vector theFunctions, Vector theBounds, Vector theEncode)
- Make a Type 3 Stitching function
- Parameters:
- theDomain - Vector objects of Double objects.
This is the domain of the function.
See page 264 of the PDF 1.3 Spec.
- theRange - Vector objects of Double objects.
This is the Range of the function.
See page 264 of the PDF 1.3 Spec.
- theFunctions - A Vector of the PDFFunction objects that the stitching function stitches.
This attributed is required.
It is described on page 269 of the PDF spec.
- theBounds - This is a vector of Doubles representing the numbers that,
in conjunction with Domain define the intervals to which each function from
the 'functions' object applies. It must be in order of increasing magnitude,
and each must be within Domain.
It basically sets how much of the gradient each function handles.
This attributed is required.
It's described on page 269 of the PDF 1.3 spec.
- theEncode - Vector objects of Double objects.
This is the linear mapping of input values intop the domain
of the function's sample table. Default is hard to represent in
ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
This attribute is required.
See page 270 in the PDF 1.3 spec.
- theFunctionType - This is the function type. It should be 3,
for a stitching function.
makeFunction
public PDFFunction makeFunction(int theNumber, int theFunctionType, Vector theDomain, Vector theRange, StringBuffer theFunctionDataStream)
- make a postscript calculator function
- Parameters:
- theNumber
- theFunctionType
- theDomain
- theRange
- theFunctionDataStream
makeLink
public PDFLink makeLink(Rectangle rect, String destination, int linkType)
- make a link object
- Parameters:
- rect - the clickable rectangle
- destination - the destination file
- linkType - the link type
- Returns: the PDFLink object created
makePage
public PDFPage makePage(PDFResources resources, PDFStream contents, int pagewidth, int pageheight, Page currentPage)
- make a /Page object
- Parameters:
- resources - resources object to use
- contents - stream object with content
- pagewidth - width of the page in points
- pageheight - height of the page in points
- Returns: the created /Page object
makePattern
public PDFPattern makePattern(int thePatternType, PDFResources theResources, int thePaintType, int theTilingType, Vector theBBox, double theXStep, double theYStep, Vector theMatrix, Vector theXUID, StringBuffer thePatternDataStream)
- Make a tiling pattern
- Parameters:
- thePatternType - the type of pattern, which is 1 for tiling.
- theResources - the resources associated with this pattern
- thePaintType - 1 or 2, colored or uncolored.
- theTilingType - 1, 2, or 3, constant spacing, no distortion, or faster tiling
- theBBox - Vector of Doubles: The pattern cell bounding box
- theXStep - horizontal spacing
- theYStep - vertical spacing
- theMatrix - Optional Vector of Doubles transformation matrix
- theXUID - Optional vector of Integers that uniquely identify the pattern
- thePatternDataStream - The stream of pattern data to be tiled.
makePattern
public PDFPattern makePattern(int thePatternType, PDFShading theShading, Vector theXUID, StringBuffer theExtGState, Vector theMatrix)
- Make a smooth shading pattern
- Parameters:
- thePatternType - the type of the pattern, which is 2, smooth shading
- theShading - the PDF Shading object that comprises this pattern
- theXUID - optional:the extended unique Identifier if used.
- theExtGState - optional: the extended graphics state, if used.
- theMatrix - Optional:Vector of Doubles that specify the matrix.
makeShading
public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, Vector theDomain, Vector theMatrix, PDFFunction theFunction)
- make a function based shading object
- Parameters:
- theShadingType - The type of shading object, which should be 1 for function
based shading.
- theColorSpace - The colorspace is 'DeviceRGB' or something similar.
- theBackground - An array of color components appropriate to the
colorspace key specifying a single color value.
This key is used by the f operator buy ignored by the sh operator.
- theBBox - Vector of double's representing a rectangle
in the coordinate space that is current at the
time of shading is imaged. Temporary clipping
boundary.
- theAntiAlias - Whether or not to anti-alias.
- theDomain - Optional vector of Doubles specifying the domain.
- theMatrix - Vector of Doubles specifying the matrix.
If it's a pattern, then the matrix maps it to pattern space.
If it's a shading, then it maps it to current user space.
It's optional, the default is the identity matrix
- theFunction - The PDF Function that maps an (x,y) location to a color
makeShading
public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, Vector theCoords, Vector theDomain, PDFFunction theFunction, Vector theExtend)
- Make an axial or radial shading object.
- Parameters:
- theShadingType - 2 or 3 for axial or radial shading
- theColorSpace - "DeviceRGB" or similar.
- theBackground - theBackground An array of color components appropriate to the
colorspace key specifying a single color value.
This key is used by the f operator buy ignored by the sh operator.
- theBBox - Vector of double's representing a rectangle
in the coordinate space that is current at the
time of shading is imaged. Temporary clipping
boundary.
- theAntiAlias - Default is false
- theCoords - Vector of four (type 2) or 6 (type 3) Double
- theDomain - Vector of Doubles specifying the domain
- theFunction - the Stitching (PDFfunction type 3) function, even if it's stitching a single function
- theExtend - Vector of Booleans of whether to extend teh start and end colors past the start and end points
The default is [false, false]
makeShading
public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, int theBitsPerFlag, Vector theDecode, PDFFunction theFunction)
- Make a free-form gouraud shaded triangle mesh, coons patch mesh, or tensor patch mesh
shading object
- Parameters:
- theShadingType - 4, 6, or 7 depending on whether it's
Free-form gouraud-shaded triangle meshes, coons patch meshes,
or tensor product patch meshes, respectively.
- theColorSpace - "DeviceRGB" or similar.
- theBackground - theBackground An array of color components appropriate to the
colorspace key specifying a single color value.
This key is used by the f operator buy ignored by the sh operator.
- theBBox - Vector of double's representing a rectangle
in the coordinate space that is current at the
time of shading is imaged. Temporary clipping
boundary.
- theAntiAlias - Default is false
- theBitsPerCoordinate - 1,2,4,8,12,16,24 or 32.
- theBitsPerComponent - 1,2,4,8,12, and 16
- theBitsPerFlag - 2,4,8.
- theDecode - Vector of Doubles see PDF 1.3 spec pages 303 to 312.
- theFunction - the PDFFunction
makeShading
public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, Vector theBackground, Vector theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, Vector theDecode, int theVerticesPerRow, PDFFunction theFunction)
- make a Lattice-Form Gouraud mesh shading object
- Parameters:
- theShadingType - 5 for lattice-Form Gouraud shaded-triangle mesh
without spaces. "Shading1" or "Sh1" are good examples.
- theColorSpace - "DeviceRGB" or similar.
- theBackground - theBackground An array of color components appropriate to the
colorspace key specifying a single color value.
This key is used by the f operator buy ignored by the sh operator.
- theBBox - Vector of double's representing a rectangle
in the coordinate space that is current at the
time of shading is imaged. Temporary clipping
boundary.
- theAntiAlias - Default is false
- theBitsPerCoordinate - 1,2,4,8,12,16, 24, or 32
- theBitsPerComponent - 1,2,4,8,12,24,32
- theDecode - Vector of Doubles. See page 305 in PDF 1.3 spec.
- theVerticesPerRow - number of vertices in each "row" of the lattice.
- theFunction - The PDFFunction that's mapped on to this shape
makeStream
public PDFStream makeStream()
- make a stream object
- Returns: the stream object created
output
public void output(OutputStream stream)
throws java.io.IOException
- write the entire document out
- Parameters:
- writer - the OutputStream to output the document to
setColorSpace
public void setColorSpace(int theColorspace)
setIDReferences
public void setIDReferences(IDReferences idReferences)
setProducer
public void setProducer(String producer)
- set the producer of the document
- Parameters:
- producer - string indicating application producing the PDF
to Class java.lang.String- the version of PDF supported
to Class java.util.Vector
- the character position of each object
to Class java.util.Vector
- the objects themselves
to Class org.apache.fop.pdf.PDFRoot
- the /Root object
to Class org.apache.fop.pdf.PDFInfo
- the /Info object
to Class org.apache.fop.pdf.PDFResources
- the /Resources object
to Class org.apache.fop.datatypes.IDReferences
- the documents idReferences
to Class org.apache.fop.datatypes.ColorSpace
- the colorspace (0=RGB, 1=CMYK) *
to Class java.util.Vector
- the XObjects
to Class java.util.Hashtable
- the XObjects Map.
Should be modified (works only for image subtype)