public class ContentGenerator extends NativeObject implements java.lang.AutoCloseable
Constructor and Description |
---|
ContentGenerator(Content content,
boolean prepend)
Create a new content generator for appending or prepending to the content of a group.
|
Modifier and Type | Method and Description |
---|---|
void |
appendContentElement(ContentElement contentElement)
Paint a content element
|
void |
clipWithPath(Path path,
InsideRule insideRule)
Intersect clip path with path.
|
void |
clipWithText(Text text)
Intersect clip path with text.
|
void |
close()
Close the object
|
static ContentGenerator |
createDynamicObject(long handle) |
void |
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 state
|
void |
transform(AffineTransform transform)
Modify the current transform matrix by concatenating the specified matrix.
|
equals, hashCode
public ContentGenerator(Content content, boolean prepend) throws java.io.IOException, CorruptException
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)java.io.IOException
- Error reading from the documentCorruptException
- The document is corruptjava.lang.IllegalArgumentException
- if the content
argument is null
java.lang.IllegalArgumentException
- if the content
object has already been closedjava.lang.IllegalArgumentException
- if the document associated with the content has already been closedjava.lang.IllegalArgumentException
- if the page/group associated with the content has already been closedpublic static ContentGenerator createDynamicObject(long handle)
public void save()
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 closedpublic void restore()
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 closedpublic void transform(AffineTransform transform)
transform
- the transform that is applied to the current transformjava.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 transform
object has already been closedjava.lang.IllegalArgumentException
- if the transform
is non-invertiblejava.lang.IllegalArgumentException
- if transform
is null
public void paintImage(Image image, Rectangle targetRect)
image
- the image to be paintedtargetRect
- the target rectangle in the current coordinate system. If targetRect is null
, the unit rectangle [0, 0, 1, 1] is used.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 image
argument is null
java.lang.IllegalArgumentException
- if the image
object has already been closedjava.lang.IllegalArgumentException
- if the image
is associated with a different documentjava.lang.IllegalArgumentException
- if targetRect
is null
public void paintImageMask(ImageMask imageMask, Rectangle targetRect, Paint paint)
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.
imageMask
- the image (stencil) masktargetRect
- the target rectangle in the current coordinate system.
If targetRect is null
, the unit rectangle [0, 0, 1, 1] is used.paint
- the paint for filling marked pixelsjava.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 imageMask
argument is null
java.lang.IllegalArgumentException
- if the imageMask
object has already been closedjava.lang.IllegalArgumentException
- if the imageMask
object is not an image maskjava.lang.IllegalArgumentException
- if the imageMask
is associated with a different documentjava.lang.IllegalArgumentException
- if the paint
argument is null
java.lang.IllegalArgumentException
- if the paint
object has already been closedjava.lang.IllegalArgumentException
- if the paint
is associated with a different documentjava.lang.IllegalArgumentException
- if targetRect
is null
public void paintPath(Path path, Fill fill, Stroke stroke)
path
- the path to be paintedfill
- the fill properties or null
if the path should not be filledstroke
- the stroke properties or null
if the path should not be strokedjava.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 path
argument is null
java.lang.IllegalArgumentException
- if the path
object has already been closedjava.lang.IllegalArgumentException
- if the fill
and stroke
arguments are both null
.java.lang.IllegalArgumentException
- if the fill
object has already been closedjava.lang.IllegalArgumentException
- if the fill
object belongs to a different documentjava.lang.IllegalArgumentException
- if the property Stroke.getPaint()
of argument stroke
is null
.java.lang.IllegalArgumentException
- if the property Stroke.getPaint()
of argument stroke
has already been closed.java.lang.IllegalArgumentException
- if the stroke
argument belongs to a different documentjava.lang.UnsupportedOperationException
- if the Paint
objects for filling and stroking use different blend modespublic void paintText(Text text) throws GenericException
text
- the text to be paintedjava.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 text
argument is null
java.lang.IllegalArgumentException
- if the text
object has already been closedjava.lang.IllegalArgumentException
- if the text
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 fontpublic void clipWithPath(Path path, InsideRule insideRule)
path
- the path to intersect with the current clip pathinsideRule
- the inside rule of the path argumentjava.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 path
argument is null
java.lang.IllegalArgumentException
- if the path
object has already been closedjava.lang.IllegalArgumentException
- if the path
is associated with a different documentjava.lang.IllegalArgumentException
- if insideRule
is null
public void clipWithText(Text text) throws GenericException
text
- the text to intersect with the current clip pathjava.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 text
argument is null
java.lang.IllegalArgumentException
- if the text
object has already been closedjava.lang.IllegalArgumentException
- if the text
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 fontpublic void paintGroup(Group group, Rectangle targetRect, Transparency transparency) throws ConformanceException
group
- the group to be paintedtargetRect
- the target rectangle in the current coordinate system.
If targetRect is null
,
a default rectangle [0, 0, width, height] is used, where width and height are the dimensions of the given group
's Size
transparency
- the transparency to be used when painting the group.
If Transparency is null
, then the group is painted opaquely.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 group
argument is null
java.lang.IllegalArgumentException
- if the group
object has already been closedjava.lang.IllegalArgumentException
- if the group
is associated with a different documentjava.lang.IllegalArgumentException
- if the group
contains no content of the content generator has not been closed yetjava.lang.IllegalArgumentException
- if the group
contains interactive elements (see Group.copyFromPage(com.pdf_tools.fourheights.pdftoolbox.pdf.Document, com.pdf_tools.fourheights.pdftoolbox.pdf.Page, com.pdf_tools.fourheights.pdftoolbox.pdf.PageCopyOptions)
)
and group has been painted before.java.lang.IllegalArgumentException
- if the group
contains interactive elements (see Group.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 the transparency
argument is not null
and has properties Transparency.getAlpha()
other than 1.0 or Transparency.getBlendMode()
other than BlendMode.NORMAL
,
and the explicitly specified conformance does not support transparency (PDF/A-1, PDF 1.0 - 1.3).public void appendContentElement(ContentElement contentElement)
contentElement
- the content element to be paintedjava.lang.IllegalStateException
- if the document associated with the content has already been closedjava.lang.IllegalStateException
- if the contentElement
object has already been closedjava.lang.IllegalStateException
- if the content object has already been closedjava.lang.IllegalArgumentException
- if the contentElement
is associated with a different documentjava.lang.IllegalArgumentException
- if the contentElement
is null
public void close() throws PdfToolboxException, java.io.IOException
close
in interface java.lang.AutoCloseable
PdfToolboxException
- only explicitly stated in a superclassjava.io.IOException