Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm working on a script that (as written) produces a large number of individual pdf pages (>100), instead of hardcoding the names of each of the outputs, I was thinking of using a wildcard. However, neither of the following seem to work:

 pdfDoc.appendPages("C:\\temp\\*.pdf")

or

 pdfDoc.appendPages("C:\\temp\\"*".pdf")

Below is the full script:

mxd = arcpy.mapping.MapDocument("C:\\temp\\Graffiti_DM3.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
graffitilyr=arcpy.mapping.ListLayers(mxd, "*", df)[0]

newquery = '"Incident_Z" =' + "'10003'"
graffitilyr.definitionQuery=newquery
features = arcpy.SearchCursor(graffitilyr)
count = 1


for feature in features:
        df.rotation = "0"
        arcpy.SelectLayerByAttribute_management(graffitilyr, "NEW_SELECTION", "FID=" + str(count))
        #df.extent = graffitilyr.getSelectedExtent(True)
        df.zoomToSelectedFeatures()
        df.scale = df.scale * .001
        arcpy.RefreshActiveView()
        df.panToExtent(graffitilyr.getSelectedExtent())
        #df.scale = "1000"
        outpdf="C:\\temp\\" + str(count) + ".pdf"
        arcpy.mapping.ExportToPDF(mxd,outpdf)
        count = count+1

pdfpath="C:\\temp\\pdfbook.pdf"
pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfpath)
for pdf in pdfs: 
        pdfDoc.appendPages("C:\\temp\\*.pdf")
pdfDoc.saveAndClose()
del features
del pdfDoc

Any help would be much appreciated

share|improve this question
2  
It seems that there are a couple of issues with your code. I know that you've gotten assistance from a few people who gave you code samples to work with. Your challenge now is getting them to fit together properly, and that is where you are having issues. As I recall, you are trying to create individual pdf's of each exported area, correct? If this is the case, then the logic for creating the pdf's needs to be inside the for loop. Right now, the pdfpath variable and logic is just sitting out there not connected to anything. You need to tie the script together. –  Get Spatial Apr 23 '13 at 2:09
1  
With the last section of code, are you trying to add all of the pdf's you just exported, into one large pdf document? If this is the case, then you need to define the pdfs variable. Right now, you are referencing it, but it is empty. It should be fed from a listing of pdf's in the directory you are saving them to. Then you could step through each one and append it to the pdfbook.pdf document. For example, this function, changed to look for pdf's would be helpful in your case: ListFiles –  Get Spatial Apr 23 '13 at 2:16
    
Great suggestions! I'm trying to add all of the pdfs exported into one large document. I was going to define the pdfs variable as a searchcursor, but I didn't think it was possible to use a search cursor outside of ArcGIS. Is it? –  David Meek Apr 23 '13 at 2:22
1  
Not sure re the searchcursor. If you are using an IDE and referencing the arcpy module, you should be able to use all the functions. The function that I listed would probably work better than a searchcursor in this instance. Also, there are specific python functions for working with the filesystem. Look at, and search the python code repository: www.python.org –  Get Spatial Apr 23 '13 at 2:31
2  
FYI a search cursor in Arc context works only on a feature class or a table. You cannot just apply a search cursor to a variable(s); you would use a list of in that case, as the answer below! There do exist 'cursors' in other languages, usually formed with queries against data. Good luck. –  Tom Apr 23 '13 at 3:31
add comment

1 Answer 1

Inside the 'for feat in feats' loop, after you create a pdf - add that path to a list.

ie

pdfList=[]

for feat in feats:
  arcpy.mapping.ExportToPDF(mxd,outpdf)
  count = count+1
  pdfList.append(outpdf)

Then use the list to append the pdfs together into one!

..

for aPdf in pdfList:
  pdfDoc.appendPages(aPdf)

pdfDoc.saveAndClose()

You were close, as @GetSpatial alluded, you just didn't populate your list.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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