Merge PDFs

Merges two or more PDF files into a single file of the same format.

Command availability: IBM RPA SaaS and IBM RPA on premises

Syntax

pdfMerge [--files(List<String>)] [--directory(String)] [--filemask(String)] --outputpath(String) (Pdf)=value (String)=file

Input parameters

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
Files files Optional List<Text>, List<PDF> List with the full paths to the PDF files, or with the variables containing the files.
Source Directory directory Optional Text Directory where files are searched.
File Mask filemask Optional Text Mask to filter PDF files by their names.

Note:Filtering occurs only by the name of the PDF file and not by its extension. In addition, the mask only applies to filtering files in the source directory.
Output Path outputpath Required Text Full path of the PDF file that will be overwritten by merging the PDF files.

Note:The name of the created PDF file must be different from the existing files.

Output Parameter

Designer mode label Script mode name Accepted variable types Description
PDF value PDF Returns the PDF file with the merging performed.
File Path file Text Returns the full path of the location where the PDF file with the merge was saved.

Example

Example 1: The Merge PDFs command merges two files, which are in PDF format and contained in a directory, so that after execution it returns the superscript merge in a third PDF file.

defVar --name mergedFilesPath --type String
defVar --name pdf --type Pdf
pdfMerge --directory "Full path of the files to be merged" --outputpath "Full path where the third pdf generated will be found\thirdFile.pdf" pdf=value mergedFilesPath=file
logMessage --message "${pdf}${mergedFilesPath}" --type "Info"
//Returns the path of the merged pdfs
Note:To test the script above, you must put both PDF files in the same directory and enter this directory in the Source Directory parameter. After that, enter the full path of the output PDF file in the Output Path parameter where the new merged PDF will be generated.

Example 2: The Merge PDFs command joins the two PDF files contained in a list, so that, after execution, it returns a new file, created with the union of the content of the two existing PDF files.

defVar --name mergedFilesPath --type String
defVar --name pdf --type Pdf
defVar --name pdfList --type List --innertype String --value "[C:\\Documents\\PDF\\pdf1.pdf,C:\\Documents\\PDF\\pdf2.pdf]"
pdfMerge --files list of paths with pdf files [C:DocumentsPDFpdf1.pdf, C:DocumentsPDFpdf2.pdf] --outputpath "Complete path where the new PDF will be generated with the merge (C:\\Documents\\PDF\\pdf3.pdf)" pdf=value mergedFilesPath=file
logMessage --message "${pdf}${mergedFilesPath}" --type "Info"
// Returns the file path in which the contents of the reported files were merged.
Note:To run the script above, you must enter the list with the path to the PDF files in the Files parameter, and also enter the path to the new PDF file in the Output Path parameter.