Merging PDF Documents (Python)¶
Merging PDF Documents (Python)¶
1# This example shows how to use IPDFUtilities to merge 3 existing PDF files
2# into a single PDF file
3
4# Create a local variable for the output toolbox
5ot = impact.gui.output_toolbox
6
7# Clear the output toolbox
8ot.clear()
9
10# Create the IPDFUtilities object
11pdfUtils = impact.creator.pdf_utilities()
12
13ot.add("PDF Library version: " + pdfUtils.library_version.as_string)
14
15# Create an array containing the 3 files to merge
16pdfFiles = [None] * 3
17pdfFiles[0] = r"D:\\Part1.pdf"
18pdfFiles[1] = r"D:\\Part2.pdf"
19pdfFiles[2] = r"D:\\Part3.pdf"
20
21# Create a single destination file
22pdfDestination = r"D:\\Merged.pdf"
23
24# Perform the PDF merge
25if pdfUtils.merge_pdf_files( pdfFiles, pdfDestination ):
26
27 ot.add("Successfully merged PDF files")
28
29else:
30
31 ot.add("Failed to merge PDF files")