Class PDXObjectImage

    • Field Detail

      • SUB_TYPE

        public static final java.lang.String SUB_TYPE
        The XObject subtype.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PDXObjectImage

        public PDXObjectImage​(PDStream imageStream,
                              java.lang.String fileSuffix)
        Standard constructor.
        Parameters:
        imageStream - The XObject is passed as a COSStream.
        fileSuffix - The file suffix, jpg/png.
      • PDXObjectImage

        public PDXObjectImage​(PDDocument doc,
                              java.lang.String fileSuffix)
        Standard constuctor.
        Parameters:
        doc - The document to store the stream in.
        fileSuffix - The file suffix, jpg/png.
    • Method Detail

      • createThumbnailXObject

        public static PDXObject createThumbnailXObject​(COSBase xobject)
                                                throws java.io.IOException
        Create the correct thumbnail from the cos base.
        Parameters:
        xobject - The cos level xobject to create.
        Returns:
        a pdmodel xobject
        Throws:
        java.io.IOException - If there is an error creating the xobject.
      • getRGBImage

        public abstract java.awt.image.BufferedImage getRGBImage()
                                                          throws java.io.IOException
        Returns an java.awt.Image, that can be used for display etc.
        Returns:
        This PDF object as an AWT image.
        Throws:
        java.io.IOException - If there is an error creating the image.
      • getSMaskImage

        public PDXObjectImage getSMaskImage()
                                     throws java.io.IOException
        Returns a PDXObjectImage of the SMask image, if there is one. See section 11.5 of the pdf specification for details on Soft Masks.
        Returns:
        the PDXObjectImage of the SMask if there is one, else null.
        Throws:
        java.io.IOException - if an I/O error occurs creating an XObject
      • applyMasks

        public java.awt.image.BufferedImage applyMasks​(java.awt.image.BufferedImage baseImage)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • hasMask

        public boolean hasMask()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • imageMask

        public java.awt.image.BufferedImage imageMask​(java.awt.image.BufferedImage baseImage)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • mask

        public java.awt.image.BufferedImage mask​(java.awt.image.BufferedImage baseImage)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • write2OutputStream

        public abstract void write2OutputStream​(java.io.OutputStream out)
                                         throws java.io.IOException
        Writes the Image to out.
        Parameters:
        out - the OutputStream that the Image is written to.
        Throws:
        java.io.IOException - when somethings wrong with out
      • write2file

        public void write2file​(java.lang.String filename)
                        throws java.io.IOException
        Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg". The suffix is automatically set by the
        Parameters:
        filename - the filename
        Throws:
        java.io.IOException - When somethings wrong with the corresponding file.
      • write2file

        public void write2file​(java.io.File file)
                        throws java.io.IOException
        Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg". The suffix is automatically set by the
        Parameters:
        file - the file
        Throws:
        java.io.IOException - When somethings wrong with the corresponding file.
      • getHeight

        public int getHeight()
        Get the height of the image.
        Returns:
        The height of the image.
      • setHeight

        public void setHeight​(int height)
        Set the height of the image.
        Parameters:
        height - The height of the image.
      • getWidth

        public int getWidth()
        Get the width of the image.
        Returns:
        The width of the image.
      • setWidth

        public void setWidth​(int width)
        Set the width of the image.
        Parameters:
        width - The width of the image.
      • getBitsPerComponent

        public int getBitsPerComponent()
        The bits per component of this image. This will return -1 if one has not been set.
        Returns:
        The number of bits per component.
      • setBitsPerComponent

        public void setBitsPerComponent​(int bpc)
        Set the number of bits per component.
        Parameters:
        bpc - The number of bits per component.
      • getColorSpace

        public PDColorSpace getColorSpace()
                                   throws java.io.IOException
        This will get the color space.
        Returns:
        The color space for this image or null if none exists or if it isn't known yet.
        Throws:
        java.io.IOException - If there is an error getting the colorspace.
      • setColorSpace

        public void setColorSpace​(PDColorSpace cs)
        This will set the color space for this image.
        Parameters:
        cs - The color space for this image.
      • getSuffix

        public java.lang.String getSuffix()
        This will get the suffix for this image type, jpg/png.
        Returns:
        The image suffix.
      • getImageMask

        public boolean getImageMask()
        Get the ImageMask flag. Used in Stencil Masking. Section 4.8.5 of the spec.
        Returns:
        The ImageMask flag. This is optional and defaults to False, so if it does not exist, we return False
      • setStencilColor

        public void setStencilColor​(PDColorState stencilColorValue)
        Set the current non stroking colorstate. It'll be used to create stencil masked images.
        Parameters:
        stencilColorValue - The non stroking colorstate
      • getStencilColor

        public PDColorState getStencilColor()
        Returns the non stroking colorstate to be used to create stencil makes images.
        Returns:
        The current non stroking colorstate.
      • getDecode

        public COSArray getDecode()
        Returns the Decode Array of an XObjectImage.
        Returns:
        the decode array
      • getMask

        public COSBase getMask()
        Returns the optional mask of a XObjectImage if there is one.
        Returns:
        The mask otherwise null.