Is there a way to automatically export a map to a folder as a pdf using an add-in? I have an add-in set up but can't find any documentation for how to accomplish the exporting part. Please let me know if you can help.
P.S: if you have any general tips for learning development with ArcObjects please leave a comment.
-Thanks.
Here is what I use to export to a BMP. There is also an ExportPDFClass() for line 8 with similar functions.
Uses ESRI.ArcGIS.Output
and VerifyFile merely checks if a file is already there and deletes it if it is. Should be fairly easy to reproduce.
Good Luck
Brent Hoskisson
public static bool ExportActiveView(IMap map, string bmpFile)
{
string pathName = "";
string fileName = "";
if (AOUtilities.VerifyFile(bmpFile, "bmp", out pathName, out fileName))
File.Delete(bmpFile);
IActiveView av = (IActiveView)map;
IExport pExport = new ExportBMPClass();
pExport.ExportFileName = bmpFile;
//pExport.Resolution = 96;
tagRECT eRect = av.ExportFrame;
IEnvelope pPBE = new EnvelopeClass();
pPBE.PutCoords(eRect.left, eRect.top, eRect.right, eRect.bottom);
pExport.PixelBounds = pPBE;
try
{
int hDC = pExport.StartExporting();
av.Output(hDC, Convert.ToInt32(pExport.Resolution), ref eRect, null, null);
pExport.FinishExporting();
return true;
}
catch
{
return false;
}
finally
{
pExport.Cleanup();
}
}
Thank you so much for your reply, I just have a few questions though... I keep getting "Interop Type ExportBMPClass cannot be embedded" errors, and I am not sure where the variables "AOUtilities" or "File" come from. Do you have any ideas? Thanks again.
-Rylan Conrad
For ExportBMPClass cannot be embedded:
Find ESRI.ArcGIS.Output Reference and view the properties. Set Embed Interop Types to false.
You can remove the VerifyFile type call and just enter the path name and file name of your output BMP into the variable initializers. Then just run a File.Exists on the file name to see if you need to delete it.
Here is another code snippet for you to explore this one creating a JPEG. Just a matter of adapting to a PDF format.
That's super helpful, but what do I pass in for the IActiveView parameter when calling the function.
It looks something like this -- CreateJPEGFromActiveView(activeView, @"c:\\....")
Thanks @DuncanHornby
Ryan
You need only to scroll down the snippet list and you will discover a function called....
Get ActiveView from ArcMap Snippet
😉
The active view could be either the Map or Layout as indicated by the object model in the help file
Duncan,
Thanks for your response. On the Get ActiveView Snippet, where does the "application" parameter come from? Thanks again.
-Rylan
The application parameter is the application, in VB you get a handle on it using the code:
My.ArcMap.Application
I don't code in c# but I would imagine its similar? Just look around at some code samples?