Select to view content in your preferred language

Problem while performing Export to PDF

3316
10
06-11-2013 09:46 AM
VikramS
Frequent Contributor
Hello all ,

I am creating a map for each feature in a feature class . I export the map to pdf using python . When i open the map ,I see there are bits and pieces of line features . I suspect I am refreshing my activeview just before exporting the pdf . Before refresh process completes , export to pdf executes and gives me this problem . I am using ArcGIS 10 . Can anyone please help me

df = arcpy.mapping.ListDataFrames(mxd)[0]
df.extent = extent
arcpy.RefreshActiveView()
arcpy.mapping.ExportToPDF(mxd,os.path.join(Report_Path,str(oid).upper()))
Tags (2)
0 Kudos
10 Replies
RhettZufelt
MVP Notable Contributor
Hello all ,  

I am creating a map for each feature in a feature class . I export the map to pdf using python . When i open the map ,I see there are bits and pieces of line features . I suspect I am refreshing my activeview just before exporting the pdf . Before refresh process completes , export to pdf executes and gives me this problem . I am using ArcGIS 10 . Can anyone please help me  
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.extent = extent
arcpy.RefreshActiveView()
mxd.save()
arcpy.mapping.ExportToPDF(mxd,os.path.join(Report_Path,str(oid).upper()))




Have you tried to save the mxd before the export so that the changes you made take effect?

R_
0 Kudos
MathewCoyle
Honored Contributor
Have you tried to save the mxd before the export so that the changes you made take effect?

R_


That really shouldn't be necessary. I'd try just adding a print statement after your refresh active view. That is all I have and it works fine.
0 Kudos
StephanieWendel
Esri Contributor
Are you running this from a stand alone script run from PythonWin, or some other kind of IDE? Or do you run your script from the Python Window within ArcMap?

We did have a bug for issues with exporting to PDF when running it in the Python Window: NIM084019 Clicking the interface while running arcpy.mapping.ExportToPDF from the Python window causes an interruption in the export process, resulting in an incomplete pdf.

If you clicked in the interface there was a chance that the interaction could interupt the process. It was reproducible at version 10 as well as 10.1. You may want to try from a stand alone script instead.

If you do run from a stand alone script, you can try adding a pause in between the refresh and the export to see if that helps.

Try adding this:
import arcpy, time

df = arcpy.mapping.ListDataFrames(mxd)[0]
df.extent = extent
arcpy.RefreshActiveView()
time.sleep(30)
arcpy.mapping.ExportToPDF(mxd,os.path.join(Report_Path,str(oid).upper()))


This will pause the code for 30 seconds. You can read more on the time module on this link: http://docs.python.org/2/library/time.html
0 Kudos
RhettZufelt
MVP Notable Contributor
That really shouldn't be necessary. I'd try just adding a print statement after your refresh active view. That is all I have and it works fine.


Well, without enough information, I was assuming that they are running this script outside of ArcMap, and not within the python window.

Not sure in the python window, as I do all my python stand alone.  When using arcpy.mapping in standalone, I absolutly have to do a mxd.save() before I export to pdf, or the export looks exactly like the one the last time I did a save regardless of the chages arcpy.mapping just made.

also, you say you put a print statement after the refresh in yours, curious what adding a print statement after the refresh does?  Print what, and how is it changing the output to pdf?

R_
0 Kudos
MathewCoyle
Honored Contributor
Well, without enough information, I was assuming that they are running this script outside of ArcMap, and not within the python window.

Not sure in the python window, as I do all my python stand alone.  When using arcpy.mapping in standalone, I absolutly have to do a mxd.save() before I export to pdf, or the export looks exactly like the one the last time I did a save regardless of the chages arcpy.mapping just made.

also, you say you put a print statement after the refresh in yours, curious what adding a print statement after the refresh does?  Print what, and how is it changing the output to pdf?

R_


I run my script stand alone and a save is not necessary. The map changes the layout and extent before exporting. The print statement isn't really necessary either as I just tested, for me it just prints where the document is being exported.
0 Kudos
RhettZufelt
MVP Notable Contributor
Was wondering if the print statement was just your "test" method.  However, was wondering if there was some "trick" that I wasn't aware of.

Thanks for the input.

Curious as to why my changes don't show until I do a save.  Might have to play around with that some more.

Are you running in ArcMap 10.1 sp1?

R_
0 Kudos
T__WayneWhitley
Honored Contributor
Yes, it could be you need to adjust params in the exportToPDF line....apparently a lot you can do there, the 10.1 doc shows the syntax with many optional parameters - start with the resolution to see if that changes your output:

ExportToPDF (map_document, out_pdf, {data_frame}, {df_export_width}, {df_export_height}, {resolution}, {image_quality}, {colorspace}, {compress_vectors}, {image_compression}, {picture_symbol}, {convert_markers}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality})


ExportToPDF (arcpy.mapping)
Desktop » Geoprocessing » ArcPy » Mapping module » Functions
http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000027000000

Enjoy,
Wayne
0 Kudos
MathewCoyle
Honored Contributor
Was wondering if the print statement was just your "test" method.  However, was wondering if there was some "trick" that I wasn't aware of.

Thanks for the input.

Curious as to why my changes don't show until I do a save.  Might have to play around with that some more.

Are you running in ArcMap 10.1 sp1?

R_


Yes I'm using 10.1 SP1. I ran into a problem a while back with a corrupted data frame throwing all kinds of weirdness when exporting to PDF messing with the scale, layout elements, etc. If it is every map you try to export not sure what would cause that.
0 Kudos
RhettZufelt
MVP Notable Contributor
I don't know what would cause it either, but after your post(s), I did some checking.

It appears that I only have to save first if I am logged in under my windoze profile.  Any other user does not have the issue.

I clobbered and re-created my profile, now it is working for me without the save also.

Go figure,

R_
0 Kudos