Class CCITTFactory
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory
-
public final class CCITTFactory extends java.lang.Object
Factory for creating a PDImageXObject containing a CCITT Fax compressed TIFF image.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
CCITTFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static PDImageXObject
createFromByteArray(PDDocument document, byte[] byteArray)
Creates a new CCITT Fax compressed image XObject from a specific image of a TIFF file stored in a byte array.static PDImageXObject
createFromByteArray(PDDocument document, byte[] byteArray, int number)
Creates a new CCITT Fax compressed image XObject from a specific image of a TIFF file stored in a byte array.static PDImageXObject
createFromFile(PDDocument document, java.io.File file)
Creates a new CCITT Fax compressed image XObject from the first image of a TIFF file.static PDImageXObject
createFromFile(PDDocument document, java.io.File file, int number)
Creates a new CCITT Fax compressed image XObject from a specific image of a TIFF file.static PDImageXObject
createFromImage(PDDocument document, java.awt.image.BufferedImage image)
Creates a new CCITT group 4 (T6) compressed image XObject from a b/w BufferedImage.static PDImageXObject
createFromRandomAccess(PDDocument document, RandomAccess reader)
Deprecated.UsecreateFromFile(PDDocument, File)
instead.static PDImageXObject
createFromRandomAccess(PDDocument document, RandomAccess reader, int number)
Deprecated.UsecreateFromFile(PDDocument, File, int)
instead.private static PDImageXObject
createFromRandomAccessImpl(PDDocument document, RandomAccess reader, int number)
Creates a new CCITT Fax compressed image XObject from a TIFF file.private static void
extractFromTiff(RandomAccess reader, java.io.OutputStream os, COSDictionary params, int number)
private static PDImageXObject
prepareImageXObject(PDDocument document, byte[] byteArray, int width, int height, PDColorSpace initColorSpace)
private static int
readlong(char endianess, RandomAccess raf)
private static int
readshort(char endianess, RandomAccess raf)
-
-
-
Method Detail
-
createFromImage
public static PDImageXObject createFromImage(PDDocument document, java.awt.image.BufferedImage image) throws java.io.IOException
Creates a new CCITT group 4 (T6) compressed image XObject from a b/w BufferedImage. This compression technique usually results in smaller images than those produced byLosslessFactory.createFromImage(PDDocument, BufferedImage)
.- Parameters:
document
- the document to create the image as part of.image
- the image.- Returns:
- a new image XObject.
- Throws:
java.io.IOException
- if there is an error creating the image.java.lang.IllegalArgumentException
- if the BufferedImage is not a b/w image.
-
createFromByteArray
public static PDImageXObject createFromByteArray(PDDocument document, byte[] byteArray) throws java.io.IOException
Creates a new CCITT Fax compressed image XObject from a specific image of a TIFF file stored in a byte array. Only single-strip CCITT T4 or T6 compressed TIFF files are supported. If you're not sure what TIFF files you have, useLosslessFactory.createFromImage(PDDocument, BufferedImage)
orcreateFromImage(PDDocument, BufferedImage)
instead.- Parameters:
document
- the document to create the image as part of.byteArray
- the TIFF file in a byte array which contains a suitable CCITT compressed image- Returns:
- a new Image XObject
- Throws:
java.io.IOException
- if there is an error reading the TIFF data.
-
createFromByteArray
public static PDImageXObject createFromByteArray(PDDocument document, byte[] byteArray, int number) throws java.io.IOException
Creates a new CCITT Fax compressed image XObject from a specific image of a TIFF file stored in a byte array. Only single-strip CCITT T4 or T6 compressed TIFF files are supported. If you're not sure what TIFF files you have, useLosslessFactory.createFromImage(PDDocument, BufferedImage)
orcreateFromImage(PDDocument, BufferedImage)
instead.- Parameters:
document
- the document to create the image as part of.byteArray
- the TIFF file in a byte array which contains a suitable CCITT compressed imagenumber
- TIFF image number, starting from 0- Returns:
- a new Image XObject
- Throws:
java.io.IOException
- if there is an error reading the TIFF data.
-
prepareImageXObject
private static PDImageXObject prepareImageXObject(PDDocument document, byte[] byteArray, int width, int height, PDColorSpace initColorSpace) throws java.io.IOException
- Throws:
java.io.IOException
-
createFromRandomAccess
@Deprecated public static PDImageXObject createFromRandomAccess(PDDocument document, RandomAccess reader) throws java.io.IOException
Deprecated.UsecreateFromFile(PDDocument, File)
instead.Creates a new CCITT Fax compressed image XObject from the first image of a TIFF file.- Parameters:
document
- the document to create the image as part of.reader
- the random access TIFF file which contains a suitable CCITT compressed image- Returns:
- a new image XObject
- Throws:
java.io.IOException
- if there is an error reading the TIFF data.
-
createFromRandomAccess
@Deprecated public static PDImageXObject createFromRandomAccess(PDDocument document, RandomAccess reader, int number) throws java.io.IOException
Deprecated.UsecreateFromFile(PDDocument, File, int)
instead.Creates a new CCITT Fax compressed image XObject from a specific image of a TIFF file.- Parameters:
document
- the document to create the image as part of.reader
- the random access TIFF file which contains a suitable CCITT compressed imagenumber
- TIFF image number, starting from 0- Returns:
- a new image XObject, or null if no such page
- Throws:
java.io.IOException
- if there is an error reading the TIFF data.
-
createFromFile
public static PDImageXObject createFromFile(PDDocument document, java.io.File file) throws java.io.IOException
Creates a new CCITT Fax compressed image XObject from the first image of a TIFF file. Only single-strip CCITT T4 or T6 compressed TIFF files are supported. If you're not sure what TIFF files you have, useLosslessFactory.createFromImage(org.apache.pdfbox.pdmodel.PDDocument, java.awt.image.BufferedImage)
orcreateFromImage(PDDocument, BufferedImage)
instead.- Parameters:
document
- the document to create the image as part of.file
- the TIFF file which contains a suitable CCITT compressed image- Returns:
- a new Image XObject
- Throws:
java.io.IOException
- if there is an error reading the TIFF data.
-
createFromFile
public static PDImageXObject createFromFile(PDDocument document, java.io.File file, int number) throws java.io.IOException
Creates a new CCITT Fax compressed image XObject from a specific image of a TIFF file. Only single-strip CCITT T4 or T6 compressed TIFF files are supported. If you're not sure what TIFF files you have, useLosslessFactory.createFromImage(PDDocument, BufferedImage)
orcreateFromImage(PDDocument, BufferedImage)
instead.- Parameters:
document
- the document to create the image as part of.file
- the TIFF file which contains a suitable CCITT compressed imagenumber
- TIFF image number, starting from 0- Returns:
- a new Image XObject
- Throws:
java.io.IOException
- if there is an error reading the TIFF data.
-
createFromRandomAccessImpl
private static PDImageXObject createFromRandomAccessImpl(PDDocument document, RandomAccess reader, int number) throws java.io.IOException
Creates a new CCITT Fax compressed image XObject from a TIFF file.- Parameters:
document
- the document to create the image as part of.reader
- the random access TIFF file which contains a suitable CCITT compressed imagenumber
- TIFF image number, starting from 0- Returns:
- a new Image XObject, or null if no such page
- Throws:
java.io.IOException
- if there is an error reading the TIFF data.
-
extractFromTiff
private static void extractFromTiff(RandomAccess reader, java.io.OutputStream os, COSDictionary params, int number) throws java.io.IOException
- Throws:
java.io.IOException
-
readshort
private static int readshort(char endianess, RandomAccess raf) throws java.io.IOException
- Throws:
java.io.IOException
-
readlong
private static int readlong(char endianess, RandomAccess raf) throws java.io.IOException
- Throws:
java.io.IOException
-
-