Hi All,
I am currently using this code to export my data driven pages to PDF, but the export seems to only export individual pages, I would like a singular output PDF with several pages instead. Does anyone know if this is possible with this tool, or do I need to use an external module to achieve this one??
mxd = arcpy.mapping.MapDocument("CURRENT") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum arcpy.mapping.ExportToPDF(mxd, r"C:\temp\MAP_" + str(pageNum) + ".pdf") del mxd
Here is the help file for the ExportToPDF tool
Cheers
Solved! Go to Solution.
If you leverage the ExportToPDF method of the mapping class you'll have to export each page one at a time and then append them into a single document. If you're using data driven pages and you want to export all of the pages to a single pdf in one go use the exportToPDF method of the data driven pages class instead of the ExportToPDF method of the mapping class.
Data Driven Pages
http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/datadrivenpages-class.htm
I've highlighted the property you're looking for below.
Export to pdf seems to default to making a multipage pdf.
So, don't change the filename in the loop.
Thanks Neil Ayres, it seems I was looking for a harder way of doing things than necessary...
Neil seems to have a much 'lighter' answer, but this is the code I used to produce the result I was looking for.
Thanks for your reply Neil, much better answer than mine.
import os, arcpy mxd = arcpy.mapping.MapDocument("CURRENT") #Create final output PDF file finalFile = r"C:\temp\BensMap.pdf" if os.path.isfile(finalFile) os.remove(finalFile) print 'Removed existing output file' finalPDF = arcpy.mapping.PDFDocumentCreate(finalFile) for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum currentPage = str(mxd.dataDrivenPages.currentPageID) pageCount = str(mxd.dataDrivenPages.pageCount) print 'Exporting page %s of %s' % (currentPage, pageCount) tmpPDF = r"C:\temp\MAP_" + str(pageNum) + ".pdf" arcpy.mapping.ExportToPDF(mxd, tmpPDF) print tmpPDF finalPDF.appendPages(tmpPDF) del tmpPDF del mxd
If you leverage the ExportToPDF method of the mapping class you'll have to export each page one at a time and then append them into a single document. If you're using data driven pages and you want to export all of the pages to a single pdf in one go use the exportToPDF method of the data driven pages class instead of the ExportToPDF method of the mapping class.
Data Driven Pages
http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/datadrivenpages-class.htm
I've highlighted the property you're looking for below.