Select to view content in your preferred language

Naming a created PDF with the DDP title

818
2
Jump to solution
05-08-2014 09:25 AM
ThomasKendall
Emerging Contributor
Good Day,

Ok so first I'm a very fresh beginner to Python and using it to help automate my map book creation.

Here is what I am looking to do.

I have several mxd files (one for left page, one for right page). I can currently use python to export each page in the map book, using DataDriven pages, to a pdf for each page.

I'm looking for a way to tell my stand alone script to name each page dependent on the name being used to sort the data driven pages.

mxdPathLeft = r"C:\MappingTemp\NorthFAC.mxd" tempMapLeft = arcpy.mapping.MapDocument(mxdPathLeft) tempDDPLeft = tempMapLeft.dataDrivenPages  # Loop creates individual pdf's for odd numbered pages # for pgNumLeft in range(1, tempDDPLeft.pageCount + 1):   temp_filename = r"C:\MappingTemp\temp_pdfs\North_" + \                             str(pgNumLeft) + "_FAC.pdf"   if os.path.exists(temp_filename):     os.remove(temp_filename)   tempDDPLeft.exportToPDF(temp_filename, "RANGE", pgNumLeft)


Is what I have for naming the files currently. I though I could just change the str(pgNumLeft) to str(tempMapLeft.title) but it just causes the script to hang and not do anything.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MikeMacRae
Frequent Contributor
Is there a title set under File-->Map Document Properties or is it empty? Do you use characters in your Title other than letters and numbers or underscores?

Also, in the string you have build to save the file to:

r"C:\MappingTemp\temp_pdfs\North_" + \ str(pgNumLeft) + "_FAC.pdf"


Remove the backslash after your first concantenation (+). So:

r"C:\MappingTemp\temp_pdfs\North_" + str(pgNumLeft) + "_FAC.pdf"

View solution in original post

0 Kudos
2 Replies
MikeMacRae
Frequent Contributor
Is there a title set under File-->Map Document Properties or is it empty? Do you use characters in your Title other than letters and numbers or underscores?

Also, in the string you have build to save the file to:

r"C:\MappingTemp\temp_pdfs\North_" + \ str(pgNumLeft) + "_FAC.pdf"


Remove the backslash after your first concantenation (+). So:

r"C:\MappingTemp\temp_pdfs\North_" + str(pgNumLeft) + "_FAC.pdf"
0 Kudos
ThomasKendall
Emerging Contributor
Mike,

Thanks for your reply. My problem was that there was no title in the document properties.

I think I have explained what I was looking for incorrectly though.

I want the page name from the data driven pages to be the name of my pdf file. Similar to if you used the export map option in ArcGIS to export data driven pages.
0 Kudos