Class ContentGenerator
- java.lang.Object
-
- com.pdf_tools.fourheights.pdftoolbox.internal.NativeBase
-
- com.pdf_tools.fourheights.pdftoolbox.internal.NativeObject
-
- com.pdf_tools.fourheights.pdftoolbox.pdf.content.ContentGenerator
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ContentGenerator extends NativeObject implements java.lang.AutoCloseable
-
-
Constructor Summary
Constructors Constructor Description ContentGenerator(Content content, boolean prepend)
Create a new content generator for appending or prepending to the content of a group.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendContentElement(ContentElement contentElement)
Paint a content elementvoid
clipWithPath(Path path, InsideRule insideRule)
Intersect clip path with path.void
clipWithText(Text text)
Intersect clip path with text.void
close()
Close the objectvoid
paintGroup(Group group, Rectangle targetRect, Transparency transparency)
Paint a group.void
paintImage(Image image, Rectangle targetRect)
Paint an image.void
paintImageMask(ImageMask imageMask, Rectangle targetRect, Paint paint)
Paint an image (stencil) mask.void
paintPath(Path path, Fill fill, Stroke stroke)
Paint a path.void
paintText(Text text)
Paint text.void
restore()
Restore the graphics state.void
save()
Save the current graphics statevoid
transform(AffineTransform transform)
Modify the current transform matrix by concatenating the specified matrix.-
Methods inherited from class com.pdf_tools.fourheights.pdftoolbox.internal.NativeObject
equals, hashCode
-
-
-
-
Constructor Detail
-
ContentGenerator
public ContentGenerator(Content content, boolean prepend)
Create a new content generator for appending or prepending to the content of a group.
- Parameters:
content
- the content object of a page or groupprepend
-true
for prepending to the content (apply content to background of page),false
for appending (apply content to foreground of page)- Throws:
java.lang.IllegalArgumentException
- if the document associated with {@link com.pdf_tools.fourheights.pdftoolbox.pdf.content.ContentGenerator# content} has already been closedjava.lang.IllegalArgumentException
- if the page or group associated with the {@link com.pdf_tools.fourheights.pdftoolbox.pdf.content.ContentGenerator# content} has already been appended or closedjava.lang.IllegalArgumentException
- ifcontent
isnull
-
-
Method Detail
-
save
public void save()
Save the current graphics state
The graphics state is stored on the graphics state stack. The following properties are affected:- The current transform matrix
- The current clip path
- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closed
-
restore
public void restore()
Restore the graphics state.
The most recently saved state is restored and removed from the graphics state stack. The following properties are affected:- The current transform matrix
- The current clip path
- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closed
-
transform
public void transform(AffineTransform transform)
Modify the current transform matrix by concatenating the specified matrix.
- Parameters:
transform
- the transform that is applied to the current transform- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if thetransform
object has already been closedjava.lang.IllegalArgumentException
- if thetransform
is non-invertiblejava.lang.IllegalArgumentException
- iftransform
isnull
-
paintImage
public void paintImage(Image image, Rectangle targetRect)
Paint an image.
- Parameters:
image
- the image to be paintedtargetRect
- the target rectangle in the current coordinate system. If targetRect isnull
, the unit rectangle [0, 0, 1, 1] is used.- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if the document associated withimage
has already been closedjava.lang.IllegalArgumentException
- if theimage
is associated with a different documentjava.lang.IllegalArgumentException
- ifimage
isnull
java.lang.IllegalArgumentException
- iftargetRect
isnull
-
paintImageMask
public void paintImageMask(ImageMask imageMask, Rectangle targetRect, Paint paint)
Paint an image (stencil) mask.
An image mask is a monochrome image, in which each sample is specified by a single bit. However, instead of being painted in opaque black and white, the image mask is treated as a stencil mask that is partly opaque and partly transparent. Sample values in the image do not represent black and white pixels; rather, they designate places on the content that should either be marked with the given paint or masked out (not marked at all). Areas that are masked out retain their former content.
The effect is like applying paint in the current color through a cut-out stencil, which allows the paint to reach the page in some places and masks it out in others.
- Parameters:
imageMask
- the image (stencil) masktargetRect
- the target rectangle in the current coordinate system. If targetRect isnull
, the unit rectangle [0, 0, 1, 1] is used.paint
- the paint for filling marked pixels- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if the document associated withimageMask
has already been closedjava.lang.IllegalArgumentException
- if theimageMask
object is not an image maskjava.lang.IllegalArgumentException
- if theimageMask
is associated with a different documentjava.lang.IllegalArgumentException
- if the document associated withpaint
has already been closedjava.lang.IllegalArgumentException
- if thepaint
is associated with a different documentjava.lang.IllegalArgumentException
- ifimageMask
isnull
java.lang.IllegalArgumentException
- iftargetRect
isnull
java.lang.IllegalArgumentException
- ifpaint
isnull
-
paintPath
public void paintPath(Path path, Fill fill, Stroke stroke)
Paint a path.
The path is first filled and then stroked The blend mode for filling and stroking must be the same.- Parameters:
path
- the path to be paintedfill
- the fill properties ornull
if the path should not be filledstroke
- the stroke properties ornull
if the path should not be stroked- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if thefill
andstroke
arguments are bothnull
.java.lang.IllegalArgumentException
- if the document associated with thefill
object has already been closedjava.lang.IllegalArgumentException
- if thefill
object belongs to a different documentjava.lang.IllegalArgumentException
- if the propertyStroke.getPaint()
of argumentstroke
isnull
.java.lang.IllegalArgumentException
- if the document associated with the propertyStroke.getPaint()
of argumentstroke
has already been closed.java.lang.IllegalArgumentException
- if thestroke
argument belongs to a different documentjava.lang.UnsupportedOperationException
- if thePaint
objects for filling and stroking use different blend modesjava.lang.IllegalArgumentException
- ifpath
isnull
-
paintText
public void paintText(Text text) throws GenericException
Paint text.
- Parameters:
text
- the text to be painted- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if thetext
is associated with a different documentGenericException
- if for some of the requested characters to paint the font's encoding is not defined or no glyph exists in the fontjava.lang.IllegalArgumentException
- iftext
isnull
-
clipWithPath
public void clipWithPath(Path path, InsideRule insideRule)
Intersect clip path with path.
Update the current clip path by intersecting with the given path.- Parameters:
path
- the path to intersect with the current clip pathinsideRule
- the inside rule of the path argument- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if thepath
is associated with a different documentjava.lang.IllegalArgumentException
- ifpath
isnull
java.lang.IllegalArgumentException
- ifinsideRule
isnull
-
clipWithText
public void clipWithText(Text text) throws GenericException
Intersect clip path with text.
Update the current clip path by intersecting with the given text.- Parameters:
text
- the text to intersect with the current clip path- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if the document associated with thetext
object has already been closedjava.lang.IllegalArgumentException
- if thetext
is associated with a different documentGenericException
- if for some of the requested characters to paint the font's encoding is not defined or no glyph exists in the fontjava.lang.IllegalArgumentException
- iftext
isnull
-
paintGroup
public void paintGroup(Group group, Rectangle targetRect, Transparency transparency) throws ConformanceException
Paint a group.
- Parameters:
group
- the group to be paintedtargetRect
- the target rectangle in the current coordinate system. If targetRect isnull
, a default rectangle [0, 0, width, height] is used, where width and height are the dimensions of the givengroup
'sSize
transparency
- the transparency to be used when painting the group. If Transparency isnull
, then the group is painted opaquely.- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the page/group associated with the content has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalArgumentException
- if the document associated with thegroup
object has already been closedjava.lang.IllegalArgumentException
- if thegroup
is associated with a different documentjava.lang.IllegalArgumentException
- if thegroup
contains no content or the content generator has not been closed yetjava.lang.IllegalArgumentException
- if thegroup
contains interactive elements (seeGroup.copyFromPage(com.pdf_tools.fourheights.pdftoolbox.pdf.Document, com.pdf_tools.fourheights.pdftoolbox.pdf.Page, com.pdf_tools.fourheights.pdftoolbox.pdf.PageCopyOptions)
) and it has been painted before.java.lang.IllegalArgumentException
- if thegroup
contains interactive elements (seeGroup.copyFromPage(com.pdf_tools.fourheights.pdftoolbox.pdf.Document, com.pdf_tools.fourheights.pdftoolbox.pdf.Page, com.pdf_tools.fourheights.pdftoolbox.pdf.PageCopyOptions)
) and the content of the content generator belongs to an annotation.ConformanceException
- if thetransparency
argument is notnull
and has propertiesTransparency.getAlpha()
other than 1.0 orTransparency.getBlendMode()
other thanBlendMode.NORMAL
, and the explicitly specified conformance does not support transparency (PDF/A-1, PDF 1.0 - 1.3).java.lang.IllegalArgumentException
- ifgroup
isnull
-
appendContentElement
public void appendContentElement(ContentElement contentElement)
Paint a content element
- Parameters:
contentElement
- the content element to be painted- Throws:
java.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if thecontentElement
object has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalArgumentException
- if thecontentElement
is associated with a different documentjava.lang.IllegalArgumentException
- ifcontentElement
isnull
-
close
public void close() throws PdfToolboxException, java.io.IOException
Close the object
Release all native resources associated with the object.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
PdfToolboxException
- only explicitly stated in a superclassjava.io.IOException
-
-