Merge DDP PDF Outputs into one file

765
1
12-27-2018 10:57 AM
Brian_McLeer
Occasional Contributor II

I have a folder of PDFs that are a 1:1 relationship with an MXD. Each plan is a floor of a building. In the screenshot below, WHBFD325 is only one floor, so no modifications need to be done to that. In the 4 files for WHBFD364, I would like to merge the 4 PDFs into one PDF with _1 being the first page, _4 being the last page. The merged file name would be WHBFD364. After the merge is complete, I would like the 4 files that end with _1, _2, _3, _4 to be deleted. I am not sure where to start, but any advice or links would really help me out.

I am looking at the PDFDoc ArpPy commands, but nothing looks promising so far. 

PDFDocument—Help | ArcGIS for Desktop 

Brian
0 Kudos
1 Reply
by Anonymous User
Not applicable

Hi Brian,

You should be able to use ArcPy to do this. In the documentation you linked Esri has a code snippet:

import arcpy, os

#Set file name and remove if it already exists
pdfPath = r"C:\Project\ParcelAtlasMapBook.pdf"
if os.path.exists(pdfPath):
    os.remove(pdfPath)

#Create the file and append pages
pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)
pdfDoc.appendPages(r"C:\Project\Title.pdf")
pdfDoc.appendPages(r"C:\Project\ParcelAtlas.pdf")
pdfDoc.appendPages(r"C:\Project\ContactInfo.pdf")

#Commit changes and delete variable reference
pdfDoc.saveAndClose()
del pdfDoc

Line 9 will create a new PDF (folder\WHBFD364.pdf would be the path passed here), then use the appendPages function in subsequent lines to append the other PDF's into the newly created one. Make sure to append them in the order you would like them to appear in the new PDF. Then, save and close the new PDF in line 15.

Once the appends are done, you could remove the old PDF files using Delete—Data Management toolbox | ArcGIS Desktop or using the os python package's remove method like in line 6.

If the ArcPy method doesn't work, there is also the PyPDF2 Python package. That package has a PdfFileMerger class that can be used to merge multiple PDF's into one. Here is a stack overflow post with some examples: python - Merge PDF files - Stack Overflow.

Hope this helps!