Class JPEGFactory

java.lang.Object
org.sejda.sambox.pdmodel.graphics.image.JPEGFactory

public final class JPEGFactory extends Object
Factory for creating a PDImageXObject containing a JPEG compressed image.
Author:
John Hewson
  • Method Details

    • createFromFile

      public static PDImageXObject createFromFile(File file) throws IOException
      Creates a new JPEG Image XObject from an input stream containing JPEG data.

      The input stream data will be preserved and embedded in the PDF file without modification.

      Parameters:
      file - a JPEG file
      Returns:
      a new Image XObject
      Throws:
      IOException - if the input stream cannot be read
    • createFromSeekableSource

      public static PDImageXObject createFromSeekableSource(org.sejda.io.SeekableSource source) throws IOException
      Throws:
      IOException
    • readJpegFile

      public static BufferedImage readJpegFile(File file) throws IOException
      Throws:
      IOException
    • createFromImage

      public static PDImageXObject createFromImage(BufferedImage image) throws IOException
      Creates a new JPEG Image XObject from a Buffered Image.
      Parameters:
      image - the buffered image to embed
      Returns:
      a new Image XObject
      Throws:
      IOException - if the JPEG data cannot be written
    • createFromImage

      public static PDImageXObject createFromImage(BufferedImage image, float quality) throws IOException
      Creates a new JPEG Image XObject from a Buffered Image and a given quality. The image will be created at 72 DPI.
      Parameters:
      image - the buffered image to embed
      quality - the desired JPEG compression quality
      Returns:
      a new Image XObject
      Throws:
      IOException - if the JPEG data cannot be written
    • createFromImage

      public static PDImageXObject createFromImage(BufferedImage image, float quality, int dpi) throws IOException
      Creates a new JPEG Image XObject from a Buffered Image, a given quality and DPI.
      Parameters:
      image - the buffered image to embed
      quality - the desired JPEG compression quality
      dpi - the desired DPI (resolution) of the JPEG
      Returns:
      a new Image XObject
      Throws:
      IOException - if the JPEG data cannot be written
    • getColorSpaceFromAWT

      public static PDColorSpace getColorSpaceFromAWT(BufferedImage awtImage)