1

This was able to combine two pdfs in a folder into one pdf, but unable to combine more than this.

import arcpy, os

# Set the workspace.
arcpy.env.workspace = r"C:\Output"

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

# List all of the pdf files in the output folder.
# pdfList is a Python List returned from the ListFiles function.
pdfList = arcpy.ListFiles("*.pdf")

#Create the file and append pages
pdfDoc = arcpy.mp.PDFDocumentCreate(pdfPath)

for f in pdfList:
    pdfDoc.appendPages(f)   

pdfDoc.saveAndClose()

del pdfDoc

Error I received

  • 1
    What's the error? appendPages for a PDF should do any number of PDFs into a single document. There isn't a limit of 2. – KHibma Jun 24 at 16:11
  • Please always provide errors as formatted text rather than pictures. – PolyGeo Jun 24 at 18:51
3

pdfDoc.appendPages doesn't know which folder to look in for the indicated PDF.

Try this:

import os
for f in pdfList:
    pdfDoc.appendPages(os.path.join (r"C:\Output", f))  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.