Class ContentGenerator

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class ContentGenerator
    extends NativeObject
    implements java.lang.AutoCloseable
    • 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 group
        prepend - 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 closed
        java.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 closed
        java.lang.IllegalArgumentException - if content is null
    • 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 closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.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 closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.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 closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalStateException - if the object has already been closed
        java.lang.IllegalArgumentException - if the transform object has already been closed
        java.lang.IllegalArgumentException - if the transform is non-invertible
        java.lang.IllegalArgumentException - if transform is null
      • paintImage

        public void paintImage​(Image image,
                               Rectangle targetRect)

        Paint an image.

        Parameters:
        image - the image to be painted
        targetRect - the target rectangle in the current coordinate system. If targetRect is null, the unit rectangle [0, 0, 1, 1] is used.
        Throws:
        java.lang.IllegalStateException - if the document associated with the content has already been closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalStateException - if the object has already been closed
        java.lang.IllegalArgumentException - if the document associated with image has already been closed
        java.lang.IllegalArgumentException - if the image is associated with a different document
        java.lang.IllegalArgumentException - if image is null
        java.lang.IllegalArgumentException - if targetRect is null
      • 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) mask
        targetRect - 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 pixels
        Throws:
        java.lang.IllegalStateException - if the document associated with the content has already been closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalStateException - if the object has already been closed
        java.lang.IllegalArgumentException - if the document associated with imageMask has already been closed
        java.lang.IllegalArgumentException - if the imageMask object is not an image mask
        java.lang.IllegalArgumentException - if the imageMask is associated with a different document
        java.lang.IllegalArgumentException - if the document associated with paint has already been closed
        java.lang.IllegalArgumentException - if the paint is associated with a different document
        java.lang.IllegalArgumentException - if imageMask is null
        java.lang.IllegalArgumentException - if targetRect is null
        java.lang.IllegalArgumentException - if paint is null
      • 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 painted
        fill - the fill properties or null if the path should not be filled
        stroke - the stroke properties or null if the path should not be stroked
        Throws:
        java.lang.IllegalStateException - if the document associated with the content has already been closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalStateException - if the object has already been closed
        java.lang.IllegalArgumentException - if the fill and stroke arguments are both null.
        java.lang.IllegalArgumentException - if the document associated with the fill object has already been closed
        java.lang.IllegalArgumentException - if the fill object belongs to a different document
        java.lang.IllegalArgumentException - if the property Stroke.getPaint() of argument stroke is null.
        java.lang.IllegalArgumentException - if the document associated with the property Stroke.getPaint() of argument stroke has already been closed.
        java.lang.IllegalArgumentException - if the stroke argument belongs to a different document
        java.lang.UnsupportedOperationException - if the Paint objects for filling and stroking use different blend modes
        java.lang.IllegalArgumentException - if path is null
      • 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 closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalStateException - if the object has already been closed
        java.lang.IllegalArgumentException - if the text is associated with a different document
        GenericException - if for some of the requested characters to paint the font's encoding is not defined or no glyph exists in the font
        java.lang.IllegalArgumentException - if text is null
      • 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 path
        insideRule - the inside rule of the path argument
        Throws:
        java.lang.IllegalStateException - if the document associated with the content has already been closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalStateException - if the object has already been closed
        java.lang.IllegalArgumentException - if the path is associated with a different document
        java.lang.IllegalArgumentException - if path is null
        java.lang.IllegalArgumentException - if insideRule is null
      • 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 closed
        java.lang.IllegalStateException - if the page/group associated with the content has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalStateException - if the object has already been closed
        java.lang.IllegalArgumentException - if the document associated with the text object has already been closed
        java.lang.IllegalArgumentException - if the text is associated with a different document
        GenericException - if for some of the requested characters to paint the font's encoding is not defined or no glyph exists in the font
        java.lang.IllegalArgumentException - if text is null
      • 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 closed
        java.lang.IllegalStateException - if the contentElement object has already been closed
        java.lang.IllegalStateException - if the content object has already been closed
        java.lang.IllegalArgumentException - if the contentElement is associated with a different document
        java.lang.IllegalArgumentException - if contentElement is null
      • close

        public void close()
                   throws PdfToolboxException,
                          java.io.IOException

        Close the object

        Release all native resources associated with the object.
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        PdfToolboxException - only explicitly stated in a superclass
        java.io.IOException