Class PDInlineImage

  • All Implemented Interfaces:
    COSObjectable, PDImage

    public final class PDInlineImage
    extends java.lang.Object
    implements PDImage
    An inline image object which uses a special syntax to express the data for a small image directly within the content stream.
    • Constructor Summary

      Constructors 
      Constructor Description
      PDInlineImage​(COSDictionary parameters, byte[] data, PDResources resources)
      Creates an inline image from the given parameters and data.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private PDColorSpace createColorSpace​(COSBase cs)  
      java.io.InputStream createInputStream()
      Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.
      java.io.InputStream createInputStream​(java.util.List<java.lang.String> stopFilters)
      Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.
      java.io.InputStream createInputStream​(DecodeOptions options)
      Returns an InputStream, passing additional options to each filter.
      int getBitsPerComponent()
      Returns bits per component of this image, or -1 if one has not been set.
      PDColorSpace getColorSpace()
      Returns the image's color space.
      COSDictionary getCOSObject()
      Convert this image to a COS object.
      byte[] getData()
      Returns the inline image data.
      COSArray getDecode()
      Returns the decode array.
      java.util.List<java.lang.String> getFilters()
      Returns A list of filters applied to this stream.
      int getHeight()
      Returns height of this image, or -1 if one has not been set.
      java.awt.image.BufferedImage getImage()
      Returns the content of this image as an AWT buffered image with an (A)RGB color space.
      java.awt.image.BufferedImage getImage​(java.awt.Rectangle region, int subsampling)
      Returns the content of this image as an AWT buffered image with an (A)RGB colored space.
      boolean getInterpolate()
      Returns true if the image should be interpolated when rendered.
      java.awt.image.BufferedImage getRawImage()
      Try to get the raw image as AWT buffered image with it's original colorspace.
      java.awt.image.WritableRaster getRawRaster()
      Return the image data as WritableRaster.
      java.awt.image.BufferedImage getStencilImage​(java.awt.Paint paint)
      Returns an ARGB image filled with the given paint and using this image as a mask.
      java.lang.String getSuffix()
      Returns the suffix for this image type, e.g.
      int getWidth()
      Returns the width of this image, or -1 if one has not been set.
      boolean isEmpty()
      Returns true if the image has no data.
      boolean isStencil()
      Returns true if the image is a stencil mask.
      void setBitsPerComponent​(int bitsPerComponent)
      Set the number of bits per component.
      void setColorSpace​(PDColorSpace colorSpace)
      Sets the color space for this image.
      void setDecode​(COSArray decode)
      Sets the decode array.
      void setFilters​(java.util.List<java.lang.String> filters)
      Sets which filters are applied to this stream.
      void setHeight​(int height)
      Sets the height of the image.
      void setInterpolate​(boolean value)
      Sets the Interpolate flag, true for high-quality image scaling.
      void setStencil​(boolean isStencil)
      Sets whether or not the image is a stencil.
      void setWidth​(int width)
      Sets the width of the image.
      private COSBase toLongName​(COSBase cs)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • rawData

        private final byte[] rawData
      • decodedData

        private final byte[] decodedData
    • Constructor Detail

      • PDInlineImage

        public PDInlineImage​(COSDictionary parameters,
                             byte[] data,
                             PDResources resources)
                      throws java.io.IOException
        Creates an inline image from the given parameters and data.
        Parameters:
        parameters - the image parameters
        data - the image data
        resources - the current resources
        Throws:
        java.io.IOException - if the stream cannot be decoded
    • Method Detail

      • getBitsPerComponent

        public int getBitsPerComponent()
        Description copied from interface: PDImage
        Returns bits per component of this image, or -1 if one has not been set.
        Specified by:
        getBitsPerComponent in interface PDImage
        Returns:
        bits per component of this image or -1
      • setBitsPerComponent

        public void setBitsPerComponent​(int bitsPerComponent)
        Description copied from interface: PDImage
        Set the number of bits per component.
        Specified by:
        setBitsPerComponent in interface PDImage
        Parameters:
        bitsPerComponent - The number of bits per component.
      • getColorSpace

        public PDColorSpace getColorSpace()
                                   throws java.io.IOException
        Description copied from interface: PDImage
        Returns the image's color space.
        Specified by:
        getColorSpace in interface PDImage
        Returns:
        the image's color space
        Throws:
        java.io.IOException - If there is an error getting the color space.
      • createColorSpace

        private PDColorSpace createColorSpace​(COSBase cs)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • setColorSpace

        public void setColorSpace​(PDColorSpace colorSpace)
        Description copied from interface: PDImage
        Sets the color space for this image.
        Specified by:
        setColorSpace in interface PDImage
        Parameters:
        colorSpace - The color space for this image.
      • getHeight

        public int getHeight()
        Description copied from interface: PDImage
        Returns height of this image, or -1 if one has not been set.
        Specified by:
        getHeight in interface PDImage
        Returns:
        height of this image or -1
      • setHeight

        public void setHeight​(int height)
        Description copied from interface: PDImage
        Sets the height of the image. This is for internal PDFBox usage and not to set the size of the image on the page.
        Specified by:
        setHeight in interface PDImage
        Parameters:
        height - The height of the image.
      • getWidth

        public int getWidth()
        Description copied from interface: PDImage
        Returns the width of this image, or -1 if one has not been set.
        Specified by:
        getWidth in interface PDImage
        Returns:
        width of this image or -1
      • setWidth

        public void setWidth​(int width)
        Description copied from interface: PDImage
        Sets the width of the image. This is for internal PDFBox usage and not to set the size of the image on the page.
        Specified by:
        setWidth in interface PDImage
        Parameters:
        width - The width of the image.
      • getInterpolate

        public boolean getInterpolate()
        Description copied from interface: PDImage
        Returns true if the image should be interpolated when rendered.
        Specified by:
        getInterpolate in interface PDImage
        Returns:
        true if the image should be interpolated when rendered
      • setInterpolate

        public void setInterpolate​(boolean value)
        Description copied from interface: PDImage
        Sets the Interpolate flag, true for high-quality image scaling.
        Specified by:
        setInterpolate in interface PDImage
        Parameters:
        value - true for high-quality image scaling
      • getFilters

        public java.util.List<java.lang.String> getFilters()
        Returns A list of filters applied to this stream.
        Returns:
        A (possibly empty) list of filters applied to this stream, never null.
      • setFilters

        public void setFilters​(java.util.List<java.lang.String> filters)
        Sets which filters are applied to this stream.
        Parameters:
        filters - the filters to apply to this stream.
      • setDecode

        public void setDecode​(COSArray decode)
        Description copied from interface: PDImage
        Sets the decode array.
        Specified by:
        setDecode in interface PDImage
        Parameters:
        decode - the new decode array.
      • getDecode

        public COSArray getDecode()
        Description copied from interface: PDImage
        Returns the decode array.
        Specified by:
        getDecode in interface PDImage
        Returns:
        the decode array
      • isStencil

        public boolean isStencil()
        Description copied from interface: PDImage
        Returns true if the image is a stencil mask.
        Specified by:
        isStencil in interface PDImage
        Returns:
        true if the image is a stencil mask
      • setStencil

        public void setStencil​(boolean isStencil)
        Description copied from interface: PDImage
        Sets whether or not the image is a stencil. This corresponds to the ImageMask entry in the image stream's dictionary.
        Specified by:
        setStencil in interface PDImage
        Parameters:
        isStencil - True to make the image a stencil.
      • createInputStream

        public java.io.InputStream createInputStream()
                                              throws java.io.IOException
        Description copied from interface: PDImage
        Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.
        Specified by:
        createInputStream in interface PDImage
        Returns:
        Decoded stream
        Throws:
        java.io.IOException - if the data could not be read.
      • createInputStream

        public java.io.InputStream createInputStream​(DecodeOptions options)
                                              throws java.io.IOException
        Description copied from interface: PDImage
        Returns an InputStream, passing additional options to each filter. As a side effect, the filterSubsampled flag is set in DecodeOptions.
        Specified by:
        createInputStream in interface PDImage
        Parameters:
        options - Additional decoding options passed to the filters used
        Returns:
        Decoded stream
        Throws:
        java.io.IOException - if the data could not be read
      • createInputStream

        public java.io.InputStream createInputStream​(java.util.List<java.lang.String> stopFilters)
                                              throws java.io.IOException
        Description copied from interface: PDImage
        Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject. The given filters will not be decoded.
        Specified by:
        createInputStream in interface PDImage
        Parameters:
        stopFilters - A list of filters to stop decoding at.
        Returns:
        Decoded stream
        Throws:
        java.io.IOException - if the data could not be read.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: PDImage
        Returns true if the image has no data.
        Specified by:
        isEmpty in interface PDImage
        Returns:
        true if the image has no data
      • getData

        public byte[] getData()
        Returns the inline image data.
        Returns:
        the inline image data
      • getImage

        public java.awt.image.BufferedImage getImage()
                                              throws java.io.IOException
        Description copied from interface: PDImage
        Returns the content of this image as an AWT buffered image with an (A)RGB color space. The size of the returned image is the larger of the size of the image itself or its mask.
        Specified by:
        getImage in interface PDImage
        Returns:
        content of this image as a buffered image.
        Throws:
        java.io.IOException - if the buffered image could not be created
      • getImage

        public java.awt.image.BufferedImage getImage​(java.awt.Rectangle region,
                                                     int subsampling)
                                              throws java.io.IOException
        Description copied from interface: PDImage
        Returns the content of this image as an AWT buffered image with an (A)RGB colored space. Only the subregion specified is rendered, and is subsampled by advancing the specified amount of rows and columns in the source image for every resulting pixel. Note that unlike the unparameterized version, this method does not cache the resulting image.
        Specified by:
        getImage in interface PDImage
        Parameters:
        region - The region of the source image to get, or null if the entire image is needed. The actual region will be clipped to the dimensions of the source image.
        subsampling - The amount of rows and columns to advance for every output pixel, a value of 1 meaning every pixel will be read
        Returns:
        subsampled content of the requested subregion as a buffered image.
        Throws:
        java.io.IOException - if the buffered image could not be created
      • getRawRaster

        public java.awt.image.WritableRaster getRawRaster()
                                                   throws java.io.IOException
        Description copied from interface: PDImage
        Return the image data as WritableRaster. You should consult the PDColorSpace returned by PDImage.getColorSpace() to know how to interpret the data in this WritableRaster. Use this if e.g. want access to the raw color information of a PDDeviceN image.
        Specified by:
        getRawRaster in interface PDImage
        Returns:
        the raw writable raster for this image
        Throws:
        java.io.IOException - if the buffered raw writable raster could not be created
      • getRawImage

        public java.awt.image.BufferedImage getRawImage()
                                                 throws java.io.IOException
        Description copied from interface: PDImage
        Try to get the raw image as AWT buffered image with it's original colorspace. No color conversion is performed. You could use the returned BufferedImage for draw operations. But this would be very slow as the color conversion would happen on demand. You rather should use PDImage.getImage() for that. This method returns null if it is not possible to map the underlying colorspace into a java.awt.ColorSpace. Use this method if you want to extract the image without loosing any color information, as no color conversion will be performed. You can alwoys use PDImage.getRawRaster(), if you want to access the raw data even if no matching java.awt.ColorSpace exists
        Specified by:
        getRawImage in interface PDImage
        Returns:
        the raw image with a java.awt.ColorSpace or null
        Throws:
        java.io.IOException - if the raw image could not be created
      • getStencilImage

        public java.awt.image.BufferedImage getStencilImage​(java.awt.Paint paint)
                                                     throws java.io.IOException
        Description copied from interface: PDImage
        Returns an ARGB image filled with the given paint and using this image as a mask.
        Specified by:
        getStencilImage in interface PDImage
        Parameters:
        paint - the paint to fill the visible portions of the image with
        Returns:
        a masked image filled with the given paint
        Throws:
        java.io.IOException - if the image cannot be read
      • getSuffix

        public java.lang.String getSuffix()
        Returns the suffix for this image type, e.g. jpg/png.
        Specified by:
        getSuffix in interface PDImage
        Returns:
        The image suffix.