Class LosslessFactory
java.lang.Object
org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory
Factory for creating a PDImageXObject containing a lossless compressed image.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static boolean
Internal, only for benchmark purpose -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static PDImageXObject
createFromGrayImage
(BufferedImage image, PDDocument document) static PDImageXObject
createFromImage
(PDDocument document, BufferedImage image) Creates a new lossless encoded image XObject from a BufferedImage.private static PDImageXObject
createFromRGBImage
(BufferedImage image, PDDocument document) private static boolean
isGrayImage
(BufferedImage image) (package private) static PDImageXObject
prepareImageXObject
(PDDocument document, byte[] byteArray, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) Create a PDImageXObject using the Flate filter.
-
Field Details
-
usePredictorEncoder
static boolean usePredictorEncoderInternal, only for benchmark purpose
-
-
Constructor Details
-
LosslessFactory
private LosslessFactory()
-
-
Method Details
-
createFromImage
public static PDImageXObject createFromImage(PDDocument document, BufferedImage image) throws IOException Creates a new lossless encoded image XObject from a BufferedImage.New for advanced users from 2.0.12 on:
If you created your image with a non standard ICC colorspace, it will be preserved. (If you load images in java using ImageIO then no need to read this segment) However a new colorspace will be created for each image. So if you create a PDF with several such images, consider replacing the colorspace with a common object to save space. This is done withPDImageXObject.getColorSpace()
andPDImageXObject.setColorSpace()
- Parameters:
document
- the document where the image will be createdimage
- the BufferedImage to embed- Returns:
- a new image XObject
- Throws:
IOException
- if something goes wrong
-
isGrayImage
-
createFromGrayImage
private static PDImageXObject createFromGrayImage(BufferedImage image, PDDocument document) throws IOException - Throws:
IOException
-
createFromRGBImage
private static PDImageXObject createFromRGBImage(BufferedImage image, PDDocument document) throws IOException - Throws:
IOException
-
prepareImageXObject
static PDImageXObject prepareImageXObject(PDDocument document, byte[] byteArray, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) throws IOException Create a PDImageXObject using the Flate filter.- Parameters:
document
- The document.byteArray
- array with data.width
- the image widthheight
- the image heightbitsPerComponent
- the bits per componentinitColorSpace
- the color space- Returns:
- the newly created PDImageXObject with the data compressed.
- Throws:
IOException
-