Package com.orsonpdf
Class Page
- java.lang.Object
-
- com.orsonpdf.PDFObject
-
- com.orsonpdf.Page
-
public class Page extends PDFObject
Represents a page in aPDFDocument. Our objective is to be able to write to the page using thePDFGraphics2Dclass (see thegetGraphics2D()method).
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,java.lang.String>alphaDictionariesprivate java.awt.geom.Rectangle2DboundsThe page bounds.private GraphicsStreamcontentsThe page contents.private java.util.List<java.lang.String>fontsOnPageThe list of font (names) used on the page.private java.util.Map<GradientPaintKey,java.lang.String>gradientPaintsOnPageA map between gradient paints and the names used to define the associated pattern in the page resources.private PDFGraphics2Dgraphics2dThe Graphics2D for writing to the page contents.private DictionarygraphicsStatesThe ExtGState dictionary for the page.private java.awt.geom.AffineTransformj2DTransformThe transform between Page and Java2D coordinates, used in Shading patterns.private PagesparentThe pages of the document.private DictionarypatternsThe pattern dictionary for this page.private java.util.Map<RadialGradientPaintKey,java.lang.String>radialGradientPaintsOnPageprivate DictionaryxObjects
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.StringaddImage(java.awt.Image img, boolean addSoftMaskImage)Adds an image to the page.(package private) java.lang.StringaddSoftMaskImage(java.awt.Image img)Adds a soft mask image to the page.private DictionarycreateDictionary()private DictionarycreateFontDictionary()private FunctioncreateFunctionForMultipleGradient(java.awt.MultipleGradientPaint mgp)(package private) java.lang.StringfindOrCreateFontReference(java.awt.Font font)Finds the font reference corresponding to the given Java2D font, creating a new one if there isn't one already.(package private) java.lang.StringfindOrCreateGSDictionary(int alpha)Returns the name of the Graphics State Dictionary that can be used for the specified alpha value - if there is no existing dictionary then a new one is created.(package private) java.lang.StringfindOrCreatePattern(java.awt.GradientPaint gp)Returns the name of the pattern for the specifiedGradientPaint, reusing an existing pattern if possible, otherwise creating a new pattern if necessary.(package private) java.lang.StringfindOrCreatePattern(java.awt.RadialGradientPaint gp)Returns the name of the pattern for the specifiedRadialGradientPaint, reusing an existing pattern if possible, otherwise creating a new pattern if necessary.java.awt.geom.Rectangle2DgetBounds()Returns a new rectangle containing the bounds for this page (as supplied to the constructor).PDFObjectgetContents()Returns thePDFObjectthat represents the page content.PDFGraphics2DgetGraphics2D()Returns thePDFGraphics2Dinstance for drawing to the page.byte[]getObjectBytes()Returns the bytes that go between the 'obj' and 'endobj' in the PDF output for this object.-
Methods inherited from class com.orsonpdf.PDFObject
getGeneration, getNumber, getReference, toPDFBytes
-
-
-
-
Field Detail
-
parent
private Pages parent
The pages of the document.
-
bounds
private java.awt.geom.Rectangle2D bounds
The page bounds.
-
contents
private GraphicsStream contents
The page contents.
-
graphics2d
private PDFGraphics2D graphics2d
The Graphics2D for writing to the page contents.
-
fontsOnPage
private java.util.List<java.lang.String> fontsOnPage
The list of font (names) used on the page. We let the parent take care of tracking the font objects.
-
gradientPaintsOnPage
private java.util.Map<GradientPaintKey,java.lang.String> gradientPaintsOnPage
A map between gradient paints and the names used to define the associated pattern in the page resources.
-
radialGradientPaintsOnPage
private java.util.Map<RadialGradientPaintKey,java.lang.String> radialGradientPaintsOnPage
-
patterns
private Dictionary patterns
The pattern dictionary for this page.
-
graphicsStates
private Dictionary graphicsStates
The ExtGState dictionary for the page.
-
j2DTransform
private java.awt.geom.AffineTransform j2DTransform
The transform between Page and Java2D coordinates, used in Shading patterns.
-
xObjects
private Dictionary xObjects
-
alphaDictionaries
private java.util.Map<java.lang.Integer,java.lang.String> alphaDictionaries
-
-
Constructor Detail
-
Page
Page(int number, int generation, Pages parent, java.awt.geom.Rectangle2D bounds)Creates a new page.- Parameters:
number- the PDF object number.generation- the PDF object generation number.parent- the parent (manages the pages in thePDFDocument).bounds- the page bounds (nullnot permitted).
-
Page
Page(int number, int generation, Pages parent, java.awt.geom.Rectangle2D bounds, boolean filter)Creates a new page.- Parameters:
number- the PDF object number.generation- the PDF object generation number.parent- the parent (manages the pages in thePDFDocument).bounds- the page bounds (nullnot permitted).filter- a flag that controls whether or not the graphics stream for the page has a FlateFilter applied.- Since:
- 1.4
-
-
Method Detail
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Returns a new rectangle containing the bounds for this page (as supplied to the constructor).- Returns:
- The page bounds.
-
getContents
public PDFObject getContents()
Returns thePDFObjectthat represents the page content.- Returns:
- The
PDFObjectthat represents the page content.
-
getGraphics2D
public PDFGraphics2D getGraphics2D()
Returns thePDFGraphics2Dinstance for drawing to the page.- Returns:
- The
PDFGraphics2Dinstance for drawing to the page.
-
findOrCreateFontReference
java.lang.String findOrCreateFontReference(java.awt.Font font)
Finds the font reference corresponding to the given Java2D font, creating a new one if there isn't one already.- Parameters:
font- the AWT font.- Returns:
- The font reference.
-
createFontDictionary
private Dictionary createFontDictionary()
-
findOrCreatePattern
java.lang.String findOrCreatePattern(java.awt.GradientPaint gp)
Returns the name of the pattern for the specifiedGradientPaint, reusing an existing pattern if possible, otherwise creating a new pattern if necessary.- Parameters:
gp- the gradient (nullnot permitted).- Returns:
- The pattern name.
-
findOrCreatePattern
java.lang.String findOrCreatePattern(java.awt.RadialGradientPaint gp)
Returns the name of the pattern for the specifiedRadialGradientPaint, reusing an existing pattern if possible, otherwise creating a new pattern if necessary.- Parameters:
gp- the gradient (nullnot permitted).- Returns:
- The pattern name.
-
createFunctionForMultipleGradient
private Function createFunctionForMultipleGradient(java.awt.MultipleGradientPaint mgp)
-
findOrCreateGSDictionary
java.lang.String findOrCreateGSDictionary(int alpha)
Returns the name of the Graphics State Dictionary that can be used for the specified alpha value - if there is no existing dictionary then a new one is created.- Parameters:
alpha- the alpha value in the range 0 to 255.- Returns:
- The graphics state dictionary reference.
-
addSoftMaskImage
java.lang.String addSoftMaskImage(java.awt.Image img)
Adds a soft mask image to the page. This is called from theaddImage(java.awt.Image, boolean)method to support image transparency.- Parameters:
img- the image (nullnot permitted).- Returns:
- The soft mask image reference.
-
addImage
java.lang.String addImage(java.awt.Image img, boolean addSoftMaskImage)Adds an image to the page. This creates the required PDF object, as well as adding a reference in thexObjectsresources. You should not call this method directly, it exists for the use of thePDFGraphics2D.drawImage(java.awt.Image, int, int, int, int, java.awt.image.ImageObserver)method.- Parameters:
img- the image (nullnot permitted).- Returns:
- The image reference name.
-
getObjectBytes
public byte[] getObjectBytes()
Description copied from class:PDFObjectReturns the bytes that go between the 'obj' and 'endobj' in the PDF output for this object.- Specified by:
getObjectBytesin classPDFObject- Returns:
- A byte array.
-
createDictionary
private Dictionary createDictionary()
-
-