How to check for a saved printer and uncheck the use printer paper settings option
Development licensing
Deployment licensing
ArcView
ArcView
ArcEditor
ArcEditor
ArcInfo
ArcInfo
Engine Developer Kit
Engine Runtime
Checking for a saved printer and unchecking the use printer paper settings
Any check for the map document's printer name must be contained in an error handling statement, because if the printer is invalid, the check will generate an error. See the following code example:
[C#]
/* Try and get the name of the printer. If it doesn't exist, set bNeedPrinter to true.* This has to be in a try/catch block because the reference to m_MapDoc.Printer.Paper.PrinterName* will throw an exception if the map was saved with use printer paper settings options and the defined * printer is not on the system.*/try
{
/* Print the current printer's name. */
System.Console.WriteLine("Map Document's current printer is " + m_MapDoc.Printer.Paper.PrinterName);
bNeedPrinter = false;
}
catch
{
/* If an exception is thrown, the printer is invalid. */
System.Console.WriteLine("Map Document's current printer is invalid.");
bNeedPrinter = true;
}
[VB.NET]
' Try and get the name of the printer. If it doesn't exist, then set bNeedPrinter to true.' This has to be in a try/catch block because the reference to m_MapDoc.Printer.Paper.PrinterName' will throw an exception if the map was saved with use printer paper settings option and the defined ' printer is not on the system.Try' Print the current printer's name.
System.Console.WriteLine("Map Document's current printer is " + m_MapDoc.Printer.Paper.PrinterName)
bNeedPrinter = FalseCatch' If an exception is thrown, the printer is invalid.
System.Console.WriteLine("Map Document's current printer is invalid.")
bNeedPrinter = TrueEndTry
Determining invalid printer name
If it is determined that the printer name is invalid, either the map was saved with the use printer paper settings unchecked or the printer the map was saved with is no longer available. To turn off the use printer paper settings, change the PageLayout.Page FormID to the correct size. This can either be one of the esriPageFormID constants or esriPageFormCUSTOM. If esriPageFormCUSTOM is used, the page's PutCustomSize method should be used to place the appropriate dimensions into the page layout. See the following code example:
[C#]
if (bNeedPrinter)
{
/* If the document's printer is invalid, assign the page size explicitly.* This is necessary because the document's printer cannot provide a page size. */if (docPage.StretchGraphicsWithPage == true)
{
/* If the Scale Graphics to Page Size check box is selected, clear it. */
docPage.StretchGraphicsWithPage = false;
}
/* This line clears the Use Printer Paper Settings check box. */
docPage.FormID = esriPageFormID.esriPageFormCUSTOM;
/* Place the correct custom size into the page. */
docPage.PutCustomSize(dPageWidth, dPageHeight);
}
[VB.NET]
If (bNeedPrinter) Then' If the document's printer is invalid, assign the page size explicitly.' This is necessary because the document's printer cannot provide a page size. If (docPage.StretchGraphicsWithPage = True) Then'If the Scale Graphics to Page Size check box is selected, clear it.
docPage.StretchGraphicsWithPage = FalseEndIf' This line clears the Use Printer Paper Settings check box.
docPage.FormID = esriPageFormID.esriPageFormCUSTOM
' Place the correct custom size into the page. */
docPage.PutCustomSize(dPageWidth, dPageHeight)
EndIf