Extracting images from PDF files
Learn how to extract an entire page as image, or how to extract a specific region from a page as image with aid of the Region Selector tool within IBM RPA Studio.
Before you begin
Before you extract images from a PDF file, you must open a PDF instance. If you use the Region Selector tool, it automatically adds the command to open the PDF file. For more information, see Opening, closing, and saving PDF files.
Extract an entire page as image
Add the Get PDF Image (pdfImage
) command to your script, and enter the PDF file and page that you want to get the image. Read this command's specification for
examples on how to use it.
Extract a specific region from a page as image
Use the Region Selector tool within IBM RPA Studio to snip and get a region-delimited part of a PDF page:
- Open this tool by clicking Tools > Region Selector.
- From the Selection tab, select
Image
. - Drag the cursor around the region that you want to get.
It automatically prompts the Get PDF Image (pdfImage
) command to you. In the Image output's parameter, enter the variable to store the image
during the bot runtime, and click Save.

What to do next
The Get PDF Image (pdfImage
) command stores the image at the bot runtime only. If you want to save the image as bitmap, JPEG, or PNG to a directory, use the Save Image (saveImage
) command.
The following code sample shows how to save the image that is gotten from the PDF file as a PNG file:
defVar --name savedImagePath --type String
defVar --name pdfInstance --type Pdf
defVar --name pdfImage --type Image
defVar --name desktopFolder --type String
// Gets the path of the Desktop folder
getSpecialFolder --folder "Desktop" desktopFolder=value
// Opens the "i_9_form_template.pdf" file as a PDF instance
pdfOpen --file "${desktopFolder}\\i_9_form_template.pdf" pdfInstance=value
// Gets the image from a specific region of the PDF file
pdfImage --useregion --region "755,36,127,76" --page 1 --dpix 110 --dpiy 110 --file ${pdfInstance} pdfImage=value
// Saves the image in the Desktop folder
saveImage --image ${pdfImage} --directory "${desktopFolder}" --file pdf_region_image --format "Png" savedImagePath=value
// Logs the file path of the saved image
logMessage --message "Your image is saved on \"${savedImagePath}\"." --type "Info"
Download the sample PDF file to use in the previous example and paste it to the Desktop folder: