Count PDF File Pages

Counts the number of pages in a PDF file.

Command availability: IBM RPA SaaS and IBM RPA on premises

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

pdfCount --file(Pdf) (Numeric)=value

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
PDF file Required Text PDF file to have the number of pages counted.

Output parameter

Designer mode label Script mode name Accepted variable types Description
Number of pages value Number Returns the number of pages in the PDF file.

Example

The Count PDF Pages command counts the number of pages in the specified file and returns the number of pages in a variable.

defVar --name filePdfOpened --type Pdf
defVar --name pathFilePdf --type String
defVar --name numberOfPages --type Numeric
pdfOpen --file "pdf1.pdf" filePdfOpened=value pathFilePdf=file
pdfCount --file ${filePdfOpened} numberOfPages=value
logMessage --message "Number of pages:${numberOfPages}" --type "Info"
pdfClose --file ${filePdfOpened}
//The contents of the numberOfPages variable are displayed in the console by the command Log Message.
Important:To run the sample script, you would use the path to a PDF file in the Path parameter of the Open PDF File (pdfOpen) command.