Class PdfImageXObject


public class PdfImageXObject extends PdfXObject
A wrapper for Image XObject. ISO 32000-1, 8.9 Images.
  • Constructor Details

  • Method Details

    • getWidth

      public float getWidth()
      Gets width of image, Width key.
      Overrides:
      getWidth in class PdfXObject
      Returns:
      float value.
    • getHeight

      public float getHeight()
      Gets height of image, Height key.
      Overrides:
      getHeight in class PdfXObject
      Returns:
      float value.
    • flush

      public void flush()
      To manually flush a PdfObject behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference. Basically this means that before flushing you need to explicitly call PdfObjectWrapper.makeIndirect(PdfDocument). For example: wrapperInstance.makeIndirect(document).flush(); Note, that not every wrapper require this, only those that have such warning in documentation.
      Overrides:
      flush in class PdfObjectWrapper<PdfStream>
    • copyTo

      public PdfImageXObject copyTo (PdfDocument document)
      Copy Image XObject to the specified document.
      Parameters:
      document - target document
      Returns:
      just created instance of PdfImageXObject.
    • getBufferedImage

      public BufferedImage getBufferedImage() throws IOException
      Gets image bytes, wrapped with buffered image.
      Returns:
      BufferedImage image.
      Throws:
      IOException - if an error occurs during reading.
    • getImageBytes

      public byte[] getImageBytes()
      Gets decoded image bytes.
      Returns:
      byte array.
    • getImageBytes

      public byte[] getImageBytes (boolean decoded)
      Gets image bytes. Note, PdfName.DCTDecode, PdfName.JBIG2Decode and PdfName.JPXDecode filters will be ignored.
      Parameters:
      decoded - if true, decodes stream bytes.
      Returns:
      byte array.
    • identifyImageType

      public ImageType identifyImageType()
      Identifies the type of the image that is stored in the bytes of this PdfImageXObject. Note that this has nothing to do with the original type of the image. For instance, the return value of this method will never be ImageType.PNG as we lose this information when converting a PNG image into something that can be put into a PDF file. The possible values are: ImageType.JPEG, ImageType.JPEG2000, ImageType.JBIG2, ImageType.TIFF, ImageType.PNG
      Returns:
      the identified type of image
    • identifyImageFileExtension

      public String identifyImageFileExtension()
      Identifies recommended file extension to store the bytes of this PdfImageXObject. Possible values are: 'png', 'jpg', 'jp2', 'tif', 'jbig2'. This extension can later be used together with the result of getImageBytes().
      Returns:
      a String with recommended file extension
      See Also:
    • put

      public PdfImageXObject put (PdfName key, PdfObject value)
      Puts the value into Image XObject dictionary and associates it with the specified key. If the key is already present, it will override the old value with the specified one.
      Parameters:
      key - key to insert or to override
      value - the value to associate with the specified key
      Returns:
      object itself.