Printing to PDF Issues

622
8
08-23-2010 09:51 AM
JeffGiesler
Occasional Contributor
Hello Everyone,
I am having trouble printing to PFD using C#.  The code outputs the map with everything it is suppose to have but it creates a much smaller pdf the what I have set for the page layout. For example, my page layout is 8.5 by 11 landscape but my document comes out as 4.4 by 3.4 inches.  I am not sure what I am missing.  I have tried the changing the resolution to 96dpi but it changes nothing.  Any help would be great.  My code is posted below.
Cheers,
Jeff
IMxDocument mxDoc = (IMxDocument)esriApp.Document;
int hdc = 0;
string path = textBox3.Text;
string VendorID = textBox1.Text;
ESRI.ArcGIS.Display.
tagRECT pExportFrame = mxDoc.ActiveView.ExportFrame;
IEnvelope env = new EnvelopeClass();
env.PutCoords(pExportFrame.left, pExportFrame.top, (pExportFrame.right) , (pExportFrame.bottom) );
IExport exOP = new ExportPDFClass();
exOP.PixelBounds = env;
exOP.ExportFileName = path +
"\\" + VendorID+".pdf";
try
{
hdc = exOP.StartExporting();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
mxDoc.ActiveView.Output(hdc, 300,
ref pExportFrame, null, null);
exOP.FinishExporting();
0 Kudos
8 Replies
JeffGiesler
Occasional Contributor
Figured it out. For anyone that runs into the same problem here is my code.
int ISR = 96;
int OR = 300;
IMxDocument mxDoc = (IMxDocument)esriApp.Document;
int hdc = 0;
string path = textBox3.Text;
string VendorID = textBox1.Text;
ESRI.ArcGIS.Display.tagRECT pExportFrame;
IEnvelope env = newEnvelopeClass();
// resize the map from screen size to paper size. This is what I was missing.
pExportFrame.left = 0;
pExportFrame.top = 0;
pExportFrame.right = mxDoc.ActiveView.ExportFrame.right * (OR / ISR);
pExportFrame.bottom = mxDoc.ActiveView.ExportFrame.bottom * (OR / ISR);
env.PutCoords(pExportFrame.left, pExportFrame.top, pExportFrame.right , pExportFrame.bottom);
IExport exOP = newExportPDFClass();
exOP.PixelBounds = env;
exOP.ExportFileName = path + "\\" + VendorID+".pdf";
hdc = exOP.StartExporting();
mxDoc.ActiveView.Output(hdc, 96,ref pExportFrame, null, null);
exOP.FinishExporting();

Here is a link to help as well.
http://edndoc.esri.com/arcobjects/9.1/Samples/Cartography/Printing_and_Exporting/ExportActiveView.ht...

Cheers,
Jeff
0 Kudos
CaleBerkey
New Contributor
Hello Jeff,

What is the ExportPDFClass you reference?

Thanks,

Cale
0 Kudos
JeffGiesler
Occasional Contributor
Cale,
I think you are looking for ESRI.ArcGIS.Output.
Let me know if that helped or if I can help you out in any other way.
Cheers,
Jeff
0 Kudos
CaleBerkey
New Contributor
Jeff,

Thanks!  For some reason I couldn't find any documentation on it.

Cale
0 Kudos
JeffGiesler
Occasional Contributor
Cale,
I know how you feel.  I look forever to find something.  I think I found it in a thread somewhere and a lot of messing around.
Cheers,
Jeff
0 Kudos
CaleBerkey
New Contributor
Jeff,

I ran across this while delving deeper into the object model:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/000100000026000000.ht...

It's a developer sample for exporting the activeview to relevant formats.  Looks like the updated version of the link you shared.

C
0 Kudos
JeffGiesler
Occasional Contributor
Thanks
Jeff
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
0 Kudos