Select to view content in your preferred language

Append Existing PDF Document with python

3223
1
01-25-2012 10:10 AM
JohnLay
Frequent Contributor
I am just starting to work with python scripts, so any help would be greatly appreciated.

I am trying to append an existing PDF document with a single page exported from a Data Drive Page MXD, but I'm having difficulty.

The code is as follows:

import arcpy, os, string

# Script arguments
Page = str(arcpy.GetParameter(0))
outPDFpath = arcpy.GetParameterAsText(1) #Working folder
finalPdf = arcpy.GetParameterAsText(2) #Existing PDF file

#Export Section Map
mxd = arcpy.mapping.MapDocument(r"CURRENT")
ddp = mxd.dataDrivenPages
ddp.currentPageID = int(Page)
tmpPdf = outPDFpath + "temp.pdf"
ddp.exportToPDF(tmpPdf, "CURRENT", resolution = 175)
finalPdf.appendPages(tmpPdf)
os.remove(tmpPdf)
del mxd, ddp

I continue to get the following error:

Traceback (most recent call last):
File "C:\~Working\tools\Scripts\AppendDDPPage.py", line 14, in <module>
finalPdf.appendPages(tmpPdf)
AttributeError: 'unicode' object has no attribute 'appendPages'

Failed to execute (ExportSinglePagefromDDP22).

Any suggestions?
0 Kudos
1 Reply
JohnLay
Frequent Contributor
I figured it out. I need to open the PDF document first.

Page = str(arcpy.GetParameter(0))
outPDFpath = arcpy.GetParameterAsText(1)
finalpdf_filename = arcpy.GetParameterAsText(2)
finalPdf = arcpy.mapping.PDFDocumentOpen(finalpdf_filename)

Thanks.
0 Kudos