Class ContentGenerator
- java.lang.Object
-
- com.pdftools.toolbox.internal.NativeBase
-
- com.pdftools.toolbox.internal.NativeObject
-
- com.pdftools.toolbox.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 voidappendContentElement(ContentElement contentElement)Paint a content elementvoidclipWithPath(Path path, InsideRule insideRule)Intersect clip path with path.voidclipWithText(Text text)Intersect clip path with text.voidclose()Close the objectvoidpaintGroup(Group group, Rectangle targetRect, Transparency transparency)Paint a group.voidpaintImage(Image image, Rectangle targetRect)Paint an image.voidpaintImageMask(ImageMask imageMask, Rectangle targetRect, Paint paint)Paint an image (stencil) mask.voidpaintPath(Path path, Fill fill, Stroke stroke)Paint a path.voidpaintText(Text text)Paint text.voidrestore()Restore the graphics state.voidsave()Save the current graphics statevoidstopTagging()Stop tagging content.voidtagAs(Node node)Associate content created following this call with the supplied element of the document structure tree.voidtagAs(Node node, java.lang.String language)Associate content created following this call with the supplied element of the document structure tree.voidtagAsArtifact(ArtifactType type)Tag all content created after this call as a artifact.voidtransform(AffineTransform transform)Modify the current transform matrix by concatenating the specified matrix.-
Methods inherited from class com.pdftools.toolbox.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-truefor prepending to the content (apply content to background of page),falsefor appending (apply content to foreground of page)- Throws:
java.lang.IllegalArgumentException- if the document associated with {@link com.pdftools.toolbox.pdf.content.ContentGenerator# content} has already been closedjava.lang.IllegalArgumentException- if the page or group associated with the {@link com.pdftools.toolbox.pdf.content.ContentGenerator# content} has already been appended or closedjava.lang.IllegalArgumentException- ifcontentisnull
-
-
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 thetransformobject has already been closedjava.lang.IllegalArgumentException- if thetransformis non-invertiblejava.lang.IllegalArgumentException- iftransformisnull
-
tagAs
public void tagAs(Node node) throws UnsupportedFeatureException
Associate content created following this call with the supplied element of the document structure tree.- Parameters:
node- the tag to be applied to the marked content- Throws:
java.lang.IllegalStateException- if the document associated with the content has already been closedUnsupportedFeatureException- if trying to tag in a content generator not associated with a pagejava.lang.IllegalArgumentException- if thenodehas a tag value that is not allowed (not part of PDF 1.7 specification and not in RoleMap)java.lang.IllegalArgumentException- ifnodeisnull
-
tagAs
public void tagAs(Node node, java.lang.String language) throws UnsupportedFeatureException
Associate content created following this call with the supplied element of the document structure tree.- Parameters:
node- the tag to be applied to the marked contentlanguage-The language code that specifies the language of the tagged content.
Specifying the language is highly recommended for PDF/A level A conformance.
The codes are defined in BCP 47 and ISO 3166:2013 and can be obtained from the Internet Engineering Task Force and the International Organization for Standardization.
If no code is set, the language will be specified as unknown.
Examples:
- "en"
- "en-US"
- "de"
- "de-CH"
- "fr-FR"
- "zxx" (for non linguistic content)
Default:
null(unknown)- Throws:
java.lang.IllegalStateException- if the document associated with the content has already been closedUnsupportedFeatureException- if trying to tag in a content generator not associated with a pagejava.lang.IllegalArgumentException- if thenodehas a tag value that is not allowed (not part of PDF 1.7 specification and not in RoleMap)java.lang.IllegalArgumentException- ifnodeisnull
-
tagAsArtifact
public void tagAsArtifact(ArtifactType type)
Tag all content created after this call as a artifact.- Parameters:
type- the artifact type- Throws:
java.lang.IllegalStateException- if the document associated with the content has already been closedjava.lang.IllegalArgumentException- iftypeisnull
-
stopTagging
public void stopTagging()
Stop tagging content.- Throws:
java.lang.IllegalStateException- if the document associated with the content has already been closed
-
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 withimagehas already been closedjava.lang.IllegalArgumentException- if theimageis associated with a different documentjava.lang.IllegalArgumentException- ifimageisnulljava.lang.IllegalArgumentException- iftargetRectisnull
-
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 withimageMaskhas already been closedjava.lang.IllegalArgumentException- if theimageMaskobject is not an image maskjava.lang.IllegalArgumentException- if theimageMaskis associated with a different documentjava.lang.IllegalArgumentException- if the document associated withpainthas already been closedjava.lang.IllegalArgumentException- if thepaintis associated with a different documentjava.lang.IllegalArgumentException- ifimageMaskisnulljava.lang.IllegalArgumentException- iftargetRectisnulljava.lang.IllegalArgumentException- ifpaintisnull
-
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 ornullif the path should not be filledstroke- the stroke properties ornullif 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 thefillandstrokearguments are bothnull.java.lang.IllegalArgumentException- if the document associated with thefillobject has already been closedjava.lang.IllegalArgumentException- if thefillobject belongs to a different documentjava.lang.IllegalArgumentException- if the propertyStroke.getPaint()of argumentstrokeisnull.java.lang.IllegalArgumentException- if the document associated with the propertyStroke.getPaint()of argumentstrokehas already been closed.java.lang.IllegalArgumentException- if thestrokeargument belongs to a different documentjava.lang.UnsupportedOperationException- if thePaintobjects for filling and stroking use different blend modesjava.lang.IllegalArgumentException- ifpathisnull
-
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 thetextis 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- iftextisnull
-
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 thepathis associated with a different documentjava.lang.IllegalArgumentException- ifpathisnulljava.lang.IllegalArgumentException- ifinsideRuleisnull
-
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 thetextobject has already been closedjava.lang.IllegalArgumentException- if thetextis 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- iftextisnull
-
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'sSizetransparency- 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 thegroupobject has already been closedjava.lang.IllegalArgumentException- if thegroupis associated with a different documentjava.lang.IllegalArgumentException- if thegroupcontains no content or the content generator has not been closed yetjava.lang.IllegalArgumentException- if thegroupcontains interactive elements (seeGroup.copyFromPage(com.pdftools.toolbox.pdf.Document, com.pdftools.toolbox.pdf.Page, com.pdftools.toolbox.pdf.PageCopyOptions)) and it has been painted before.java.lang.IllegalArgumentException- if thegroupcontains interactive elements (seeGroup.copyFromPage(com.pdftools.toolbox.pdf.Document, com.pdftools.toolbox.pdf.Page, com.pdftools.toolbox.pdf.PageCopyOptions)) and the content of the content generator belongs to an annotation.ConformanceException- if thetransparencyargument is notnulland 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- ifgroupisnull
-
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 thecontentElementobject has already been closedjava.lang.IllegalStateException- if the content object has already been closedjava.lang.IllegalArgumentException- if thecontentElementis associated with a different documentjava.lang.IllegalArgumentException- ifcontentElementisnull
-
close
public void close() throws ToolboxException, java.io.IOExceptionClose the object
Release all native resources associated with the object.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
ToolboxException- only explicitly stated in a superclassjava.io.IOException
-
-