Package com.pdftools.toolbox.pdf.content
Class ImageMask
- java.lang.Object
-
- com.pdftools.toolbox.internal.NativeBase
-
- com.pdftools.toolbox.internal.NativeObject
-
- com.pdftools.toolbox.pdf.content.ImageMask
-
public class ImageMask extends NativeObject
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ImageMaskcreate(Document targetDocument, Stream stream)Create an image mask object from image data.voidextract(Stream stream)Extract image mask from PDFvoidextract(Stream stream, ImageType imageType)Extract image mask from PDFdoublegetResolution(AffineTransform transform)The resolution of an image mask on the page in DPI (dots per inch).SizegetSize()The size of the image mask in samples.-
Methods inherited from class com.pdftools.toolbox.internal.NativeObject
equals, hashCode
-
-
-
-
Method Detail
-
create
public static ImageMask create(Document targetDocument, Stream stream) throws java.io.IOException, UnknownFormatException, CorruptException
Create an image mask object from image data.
Supported formats are:- BMP
- DIB
- JBIG2
- PNG
- GIF
- Parameters:
targetDocument- the output document with which the returned object is associatedstream- the image data stream- Returns:
- the newly created image mask object
- Throws:
java.io.IOException- Error reading from the image or writing to the documentUnknownFormatException- The image data has an unknown format or the format is not suitable for an image maskCorruptException- The image data is corruptjava.lang.IllegalArgumentException- if thetargetDocumentargument has already been closedjava.lang.IllegalArgumentException- if thetargetDocumentargument is read-onlyjava.lang.IllegalArgumentException- if thestreamargument isnulljava.lang.IllegalArgumentException- iftargetDocumentisnulljava.lang.IllegalArgumentException- ifstreamisnull
-
extract
public void extract(Stream stream) throws GenericException
Extract image mask from PDF
Facilitate the extraction of image masks from a specified page within a PDF, outputting them in the
imageTypeformat.By default
imageTypetakes the valueImageType.TIFF.Key considerations include:
- The extraction process isolates the image from the page's resources, neglecting any contextual attributes from the PDF page. Consequently, the original resolution and modifications—such as scaling, rotation, or cropping—that influence the image's appearance on the page are not preserved in the extracted image mask.
-
In instances where a
GenericExceptionerror arises, the output file may be compromised and rendered unusable.
This method is designed to efficiently retrieve image masks without their page-specific modifications, ensuring a straightforward extraction process.
- Parameters:
stream- The image mask data stream.- Throws:
java.lang.IllegalArgumentException- if thestreamargument is nulljava.lang.IllegalStateException- if the image has already been closedGenericException- if image extraction failsjava.lang.IllegalArgumentException- ifstreamisnull
-
extract
public void extract(Stream stream, ImageType imageType) throws GenericException
Extract image mask from PDF
Facilitate the extraction of image masks from a specified page within a PDF, outputting them in the
imageTypeformat.By default
imageTypetakes the valueImageType.TIFF.Key considerations include:
- The extraction process isolates the image from the page's resources, neglecting any contextual attributes from the PDF page. Consequently, the original resolution and modifications—such as scaling, rotation, or cropping—that influence the image's appearance on the page are not preserved in the extracted image mask.
-
In instances where a
GenericExceptionerror arises, the output file may be compromised and rendered unusable.
This method is designed to efficiently retrieve image masks without their page-specific modifications, ensuring a straightforward extraction process.
- Parameters:
stream- The image mask data stream.imageType-- Throws:
java.lang.IllegalArgumentException- if thestreamargument is nulljava.lang.IllegalStateException- if the image has already been closedGenericException- if image extraction failsjava.lang.IllegalArgumentException- ifstreamisnull
-
getResolution
public double getResolution(AffineTransform transform)
The resolution of an image mask on the page in DPI (dots per inch).
The resolution is the ratio between the size of the image mask and the size it uses on the page.- Parameters:
transform- The affine transformation matrix of the image mask. Typically, this is the affine transformation matrix ofImageMaskElement.- Returns:
- The calculated resolution in DPI.
- Throws:
java.lang.IllegalArgumentException- if thetransformobject has already been closedjava.lang.IllegalArgumentException- if thetransformis non-invertiblejava.lang.IllegalArgumentException- iftransformisnull
-
getSize
public Size getSize()
The size of the image mask in samples. (Getter)
- Throws:
java.lang.IllegalStateException- if the image has already been closed
-
-