pdftools_toolbox.pdf.content.image_mask
Classes
|
- class pdftools_toolbox.pdf.content.image_mask.ImageMask(handle)[source]
Bases:
_NativeObject
- static create(target_document: Document, stream: IOBase) ImageMask [source]
Create an image mask object from image data.
Supported formats are:
BMP
DIB
JBIG2
PNG
GIF
The returned image mask object is not yet painted on any page, but it is associated with the given target document.
- Parameters:
targetDocument (pdftools_toolbox.pdf.document.Document) – the output document with which the returned object is associated
stream (io.IOBase) – the image data stream
- Returns:
the newly created image mask object
- Return type:
- Raises:
OSError – Error reading from the image or writing to the document
pdftools_toolbox.unknown_format_error.UnknownFormatError – The image data has an unknown format or the format is not suitable for an image mask
pdftools_toolbox.corrupt_error.CorruptError – The image data is corrupt
ValueError – if the targetDocument argument has already been closed
ValueError – if the targetDocument argument is read-only
ValueError – if the stream argument is None
- extract(stream: IOBase, image_type: ImageType | None = None) None [source]
Extract image mask from PDF
Facilitate the extraction of image masks from a specified page within a PDF, outputting them in the imageType format.
By default imageType takes the value
pdftools_toolbox.pdf.content.image_type.ImageType.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
pdftools_toolbox.generic_error.GenericError
error 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 (io.IOBase) – The image mask data stream.
imageType (Optional[pdftools_toolbox.pdf.content.image_type.ImageType])
- Raises:
ValueError – if the stream argument is null
StateError – if the image has already been closed
pdftools_toolbox.generic_error.GenericError – if image extraction fails
- property size: Size
The size of the image mask in samples.
- Returns:
pdftools_toolbox.geometry.integer.size.Size
- Raises:
StateError – if the image has already been closed