org.apache.pdfbox.pdmodel.graphics.image

## Class JPEGFactory

- java.lang.Object
- - org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory

    public final class JPEGFactory
    extends Object

Factory for creating a PDImageXObject containing a JPEG compressed image.

Author:
  John Hewson

### Method Summary

All Methods Static Methods Concrete Methods
`static PDImageXObject` `createFromByteArray(PDDocument document, byte[] byteArray)` Creates a new JPEG Image XObject from a byte array containing JPEG data.
`static PDImageXObject` `createFromImage(PDDocument document, BufferedImage image)` Creates a new JPEG PDImageXObject from a BufferedImage.
`static PDImageXObject` `createFromImage(PDDocument document, BufferedImage image, float quality)` Creates a new JPEG PDImageXObject from a BufferedImage and a given quality.
`static PDImageXObject` `createFromImage(PDDocument document, BufferedImage image, float quality, int dpi)` Creates a new JPEG Image XObject from a BufferedImage, a given quality and dpi metadata.
`static PDImageXObject` `createFromStream(PDDocument document, InputStream stream)` Creates a new JPEG Image XObject from an input stream containing JPEG data.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### createFromStream

    public static PDImageXObject createFromStream(PDDocument document,
                                                  InputStream stream)
                                           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:
  `document` - the document where the image will be created
  `stream` - a stream of JPEG data
Returns:
  a new Image XObject
Throws:
  `IOException` - if the input stream cannot be read

#### createFromByteArray

    public static PDImageXObject createFromByteArray(PDDocument document,
                                                     byte[] byteArray)
                                              throws IOException

Creates a new JPEG Image XObject from a byte array containing JPEG data.

Parameters:
  `document` - the document where the image will be created
  `byteArray` - bytes of JPEG image
Returns:
  a new Image XObject
Throws:
  `IOException` - if the input stream cannot be read

#### createFromImage

    public static PDImageXObject createFromImage(PDDocument document,
                                                 BufferedImage image)
                                          throws IOException

Creates a new JPEG PDImageXObject from a BufferedImage.

Do not read a JPEG image from a stream/file and call this method; you'll get more speed and quality by calling `createFromStream()` instead.

Parameters:
  `document` - the document where the image will be created
  `image` - the BufferedImage to embed
Returns:
  a new Image XObject
Throws:
  `IOException` - if the JPEG data cannot be written

#### createFromImage

    public static PDImageXObject createFromImage(PDDocument document,
                                                 BufferedImage image,
                                                 float quality)
                                          throws IOException

Creates a new JPEG PDImageXObject from a BufferedImage and a given quality.

Do not read a JPEG image from a stream/file and call this method; you'll get more speed and quality by calling `createFromStream()` instead. The image will be created with a dpi value of 72 to be stored in metadata.

Parameters:
  `document` - the document where the image will be created
  `image` - the BufferedImage to embed
  `quality` - The desired JPEG compression quality; between 0 (best compression) and 1 (best image quality). See `ImageWriteParam.setCompressionQuality(float)` for more details.
Returns:
  a new Image XObject
Throws:
  `IOException` - if the JPEG data cannot be written

#### createFromImage

    public static PDImageXObject createFromImage(PDDocument document,
                                                 BufferedImage image,
                                                 float quality,
                                                 int dpi)
                                          throws IOException

Creates a new JPEG Image XObject from a BufferedImage, a given quality and dpi metadata.

Do not read a JPEG image from a stream/file and call this method; you'll get more speed and quality by calling `createFromStream()` instead.

Parameters:
  `document` - the document where the image will be created
  `image` - the BufferedImage to embed
  `quality` - The desired JPEG compression quality; between 0 (best compression) and 1 (best image quality). See `ImageWriteParam.setCompressionQuality(float)` for more details.
  `dpi` - the desired dpi (resolution) value of the JPEG to be stored in metadata. This value has no influence on image content or size.
Returns:
  a new Image XObject
Throws:
  `IOException` - if the JPEG data cannot be written