Skip to main content

Extract Images from PDF | Capacitor Barcode Scanner

The ScanbotBarcodeSDK.extractImagesFromPdf function allows you to extract JPEG or PNG (Android only) images from a PDF file.

 // Always make sure you have a valid license on runtime via ScanbotBarcodeSDK.getLicenseInfo()
if (!(await this.isLicenseValid())) {
return;
}

try {
// Select PDF file from library
const pdfFilePath = await this.fileUtils.selectPdfFile();

const args: ExtractImagesFromPdfArguments = {
pdfFilePath: pdfFilePath,
};
await this.utils.showLoader();

const result = await ScanbotBarcodeSDK.extractImagesFromPDF(args);

this.utils.dismissLoader();

if (result.data && result.data.length > 0) {
this.router.navigate(['/image-results', JSON.stringify(result.data)]);
} else {
this.utils.showInfoAlert('No images extracted');
}
} catch (error: any) {
await this.utils.dismissLoader();

this.utils.showErrorAlert(error);
}

Handling the Result

Returned result has status property that will be OK if the extracting is finished and data property representing string array that contains URLs for extracted images.

Arguments

As in input argument object the pdfFilePath should be set, togheter with another optional properties that can help you configure the ouput images.

export interface ExtractImagesFromPdfArguments {
/**
* The location of the PDF file
*/
pdfFilePath: string;
/**
* The quality that each extracted image should have.
* This tweaks the compression, affecting the final image file size.
* (100: maximum quality, 0: minimum quality)
*
* Default value is 90
*/
quality?: number;
/**
* Integer scaling factor applied to the PDF media box frame while extracting.
* Affects the output image quality.
* In most cases the recommended value is 2 or higher.
*
* Default value is 2.
*/
scaling?: number;
/**
* Compress format used for extracted images. Android only.
*
* Default value is JPEG.
*/
compressFormat?: CompressFormat
}

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?


On this page

Scroll to top