Export PDF Bookmarks to PDF Pages (single PDF)

944
4
02-26-2014 02:10 PM
DannyLackey
New Contributor II
I have this script

import arcpy
mxd = arcpy.mapping.MapDocument("I:\GIS_Workspace\MAP\Test.mxd")
mainDF = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
arcpy.RefreshActiveView();arcpy.RefreshTOC()
arcpy.mapping.ExportToPDF (mxd,"I:\GIS_Workspace\PDF\MAP.pdf")]


...which works great if I'm just dumping out a single map without much criteria.  I've been asked to create a PDF document with multiple pages.  Each with a map corresponding to one of the bookmarks within a .mxd file.  I understand
arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
was added in ArcGIS 10.1.  I'm thinking that may hold some promise...  I've not found too much info on this in my searches...  There are more layers than just the ones needed in this .mxd, so I'd need to be able to specify which layers should apply to each bookmark (they'd all be the same for each, so hard coding would work too). 

TIA
Tags (2)
0 Kudos
4 Replies
JeffBarrette
Esri Regular Contributor
ListDataFrames was not new at 10.1.  Maybe you are talking about ListBookmarks.  There are a couple of samples in the help.

This first one shows you how to iterate through bookmarks.

http://resources.arcgis.com/en/help/main/10.2/#/ListBookmarks/00s300000060000000/

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0]
for bkmk in arcpy.mapping.ListBookmarks(mxd, data_frame=df):
    df.extent = bkmk.extent
    outFile = r"C:\Project\Output\\" + bkmk.name + ".jpg"
    arcpy.mapping.ExportToJPEG(mxd, outFile, df)
del mxd


You can easily change that to export to PDF.

The next script shows you how to append many PDFs into a single PDF.
http://resources.arcgis.com/en/help/main/10.2/#/PDFDocument/00s30000002w000000/

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")

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


Jeff
0 Kudos
DannyLackey
New Contributor II
ListDataFrames was not new at 10.1. Maybe you are talking about ListBookmarks.


Yes, sorry, that is what I meant. 

This info looks like what I need...  Going to attempt to put it to work...
0 Kudos
DannyLackey
New Contributor II
So, focusing on the exporttopdf piece at the moment... 

import arcpy
mxd = arcpy.mapping.MapDocument(r"I:\GIS_Workspace\MAP\Test.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for bkmk in arcpy.mapping.ListBookmarks(mxd, data_frame=df):
    df.extent = bkmk.extent
    outFile = r"I:\GIS_Workspace\MAP\MAP.pdf\\" + bkmk.name + ".pdf"
    arcpy.mapping.ExportToPDF(mxd, outFile, df)
del mxd


The PDF isn't coming out looking like the book mark.  The image in the PDF is quite squished together.  Also, how can I specify a specific set of layers and specific bookmarks?  As it is now, it seems to output all layers and all bookmarks.
0 Kudos
DannyLackey
New Contributor II
for bkmk in arcpy.mapping.ListBookmarks(mxd,"Bookmark1",df):


Ok, I figured out that if I replace "data_frame" with the bookmark name, I can get it to produce just that bookmark.  But I need a specific list.  Just not sure how to make it produce each specific bookmark I need.

And as for specific layers to produce, using "Layers" produces all.  But I'd like to be able to specify which layers under "Layers" output.
0 Kudos