Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

enter image description here

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?

enter image description here

share|improve this question
    
Did you try changing the printer's default settings in window's control panel? –  relima Feb 15 '11 at 18:35
    
is your windows locale set to EN_US? try EN_GB - though I would switch off Scale Map Elements and use PDF for Export - and drop the pdf directly on the HP5500.- Speed will be faster as ArcMap is slow rasterizing. –  Mapperz Feb 15 '11 at 18:47
    
@Mapperz - nice hints n tips there! It is indeed in EN_GB. –  Vidar Feb 15 '11 at 19:16
    
Hmmm still getting no where with this - even when I export as PDF - the scale is slightly out, where as an export manually in ArcMap produces a perfect scale map?!?!? –  Vidar Feb 16 '11 at 11:47
    
IPaper.FormID is not the same as IPage.FormID. ESRI's documentation states that IPaper.FormID uses the Win32 DMPAPER_xxx constants, as you mentioned, so A3 would be FormID = 8 –  Adam Armour May 12 '11 at 16:44

2 Answers 2

I fixed this problem by setting the dataframe extend to "FixedScale":

MapFrame mapFrame = ...
mapFrame.setExtentType(esriExtentTypeEnum.esriExtentScale);
mapFrame.setMapScale(printOutput.calculateScale(mapExtentEnvelope));        
share|improve this answer

I did eventually fix this by using a PrintLayout control - which although not elegant did seem to fix the printing problem. This fault has also been assigned a NIM code with ESRI (NIM065953) too. But I don't know whether they will actually fix it, I guess it's a low priority to them.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.