| ImageExtract Method |
Extract embedded image from PDF
Facilitate the extraction of images from a specified page within a PDF, outputting them in the imageType format.
By default, the method determines the format of the extracted image based on the embedded image data present within the PDF.
Users can ascertain the default image format through DefaultImageType.
It's important to note that not all image types or conversion processes are universally supported, hence adhering to the default ImageType is advisable for optimal compatibility.
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.
-
In instances where a GenericException error arises, the output file may be compromised and rendered unusable.
This method is designed to efficiently retrieve images without their page-specific modifications, ensuring a straightforward extraction process.
Namespace: PdfTools.Toolbox.Pdf.ContentAssembly: PdfTools.Toolbox (in PdfTools.Toolbox.dll) Version: 1.4.0+02318d3e3f9645a1305b87026fb971a660079e54
Syntax public void Extract(
Stream stream,
ImageType? imageType = null
)
Parameters
- stream Stream
-
The image data stream.
- imageType NullableImageType (Optional)
-
The desired image type of the extracted image stream.
If the embedded image data cannot be directly extracted to the chosen ImageType, the data is first recompressed and then extracted to the chosen ImageType.
In this case, extraction is slower and there can be some loss of image quality.
The default image type can be retrieved by calling DefaultImageType.
Exceptions Exception | Condition |
---|
ArgumentException | if the stream argument is null |
InvalidOperationException | if the image has already been closed |
GenericException | if image extraction fails |
ArgumentNullException | if stream is . |
See Also