Select to view content in your preferred language

Export Dataframe to PDF - extent problems

5030
1
04-03-2014 12:41 PM
by Anonymous User
Not applicable
Original User: Mannin

We are trying to create a new PDF for each polygon in our feature class.
The scale must stay the same, so the page size needs to change.
This also means that DataDrivenPages isn't a workable option for us for these products.
We are exporting the dataframe, not the page_layout so that we can manipulate the page sizes programatically.

My current problem is that the resulting PDF does not have the same extent as what I see in ArcMap.
I've attached images of the ArcMap dataframe (inside layout view) and the pdf export.

The exported PDF page size seems to be correct, so I believe we are converting from inches to pixels properly.
But, I don't know why the extent does appear as expected.

Any suggestions are greatly appreciated.


Here's my test code that I run from the Python window in the mxd:

import arcpy, os, math, time
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

df.scale = 31680 # set and keep dataframe scale at 1 inch = 1/2 mile

BULayer = arcpy.mapping.ListLayers(mxd,"BidUnits",df)[0]

arcpy.SelectLayerByAttribute_management(BULayer,"NEW_SELECTION","BID_UNIT = 8") #run on just one feature for testing

df.panToExtent(BULayer.getSelectedExtent()) # center dataframe on selected feature centroid

#get real world distance of selected feature - ArcMap 10.1 and later returns dataframe CS units on .getSelectedExtent call
#current dataframe CS is Web Mercator
y_dist_meters = BULayer.getSelectedExtent().YMax - BULayer.getSelectedExtent().YMin
x_dist_meters = BULayer.getSelectedExtent().XMax - BULayer.getSelectedExtent().XMin

#buffer the extent by a mile on each side
y_dist_meters += (1609*2)
x_dist_meters += (1609*2)
#convert distances to inches from meters
y_dist_inches = math.ceil(y_dist_meters * 39.3701)
x_dist_inches = math.ceil(x_dist_meters * 39.3701)

#calculate page size
y_inches = math.ceil(y_dist_inches / df.scale)
x_inches = math.ceil(x_dist_inches / df.scale)
print str(x_inches) + " x " + str(y_inches)

#set dataframe height and width
df.elementHeight = y_inches
df.elementWidth = x_inches

arcpy.RefreshActiveView()
#time.sleep(30) #test to see if a complete redraw affects results

#calculate page size in pixels based on pdf export resolution
pdfRes = 300
dfew = int(x_inches * pdfRes)
dfeh = int(y_inches * pdfRes)
PDF = "C:/gm_sts/bidunitmobilemaps/pdf/testing2.pdf"
#mxd.save() #test if mxd save affects results
arcpy.mapping.ExportToPDF(mxd,PDF,df,df_export_width=dfew,df_export_height=dfeh,resolution=pdfRes,image_quality="NORMAL",layers_attributes="NONE")
0 Kudos
1 Reply
OwenEarley
Frequent Contributor
You might want to check this out:

Bug NIM-052429

Layer.getSelectedExtent() returns a different (bigger) extent than Geometry.extent and DataFrame.zoomToSelectedFeatures().

http://support.esri.com/en/bugs/nimbus/TklNMDUyNDI5

I have just come across a similar issue today in a while exporting maps to PDF. My python script was working fine with file geodatabase data but as soon as I switched to using SDE data sources this problem emerged.

Hope this helps.
0 Kudos