Context
ArcGIS 9.2 Build 1500
- ArcObjects Windows Forms application running outside of ArcMap, similar to ArcEngine product.
- Accessing mxd to print out page layout to A3 paper. Mxd is saved with same settings as printer, see below:
- Original code was copied from PrintActive View sample on ESRI site. This sample does run in the ArcMap environment, but I don't think this should have a bearing on my problem.
Actual Problem
For some strange reason when my code prints out the map - it always prints to B5 which is obviously wrong as it should be A3. Printer complains that it doesn't have B5 - no map gets printed and misery ensues!
On further inspection of the code it seems that something strange is happening, the code below is a cut down version of the sample code just to show how you get the problem:
IPrinter docPrinter;
IPaper docPaper;
/* printdocument is from the .NET assembly system.drawing.printing */
System.Drawing.Printing.PrintDocument sysPrintDocumentDocument;
/* Now we need to get the default printer name. Since this is a generic command,
* we can't use the printername property of the document. So instead, we use the
* System.Drawing.Printing objects to find the default printer.
*/
docPrinter = new EmfPrinterClass();
sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument();
docPaper = new PaperClass();
/* testing to see if printer instantiated in sysPrintDocumentDocument is the
* default printer. It SHOULD be, but this is just a reality check.
*/
bool isDefault = sysPrintDocumentDocument.PrinterSettings.IsDefaultPrinter;
if (isDefault)
{
//FIRST STEP
//Set docPaper's printername to the printername of the default printer
docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName;
//Need to have the same paper form as the mxd
docPaper.FormID = (short) mapDocument.PageLayout.Page.FormID;
}
/* Now assign docPrinter the paper and with it the printername. This process is two steps
* because you cannot change an IPrinter's printer except by passing it as a part of
* the IPaper. That's why we setup docPrinter.Paper.PrinterName first.
*/
//SECOND STEP
docPrinter.Paper = docPaper;
when the code sets the docPaper.FormID (it's defaulted to 1 which is esrPageFormLetter) and overwrites this value with the value in the mxd (IMapDocument) mapDocument.PageLayout.Page.FormID - in this case its 13 (esrPageFormSameAsPrinter), that makes sense as we saved the mxd to "Use Printer Paper Settings" (see image above).
The 13 value that is passed seems to cause some conflict in translation to the IPaper object - because it was passed 13 it thinks that is B5 and not to try and infer out the printer settings which should be A3.
The best I can make out of this - is that it must have something to do with Windows paper size constants e.g. DMPAPER_B5 - 13 - B5 (JIS) 182 x 257 mm.
Does anyone have a clue how to get round this problem?
No comments:
Post a Comment