public void PrintActiveViewArcPressParameterized(int iResampleRatio) { /* Prints the Active View of the document with ArcPress */ IPrintAndExport PrintAndExport = new PrintAndExportClass(); IActiveView docActiveView = ArcMap.Document.ActiveView; IPrinter docPrinter; IArcPressPrinter docArcPressPrinter; string sNameRoot; short iNumPages; // assign the output path and filename. We can use the Filter property of the export object to // automatically assign the proper extension to the file. sNameRoot = ArcMap.Application.Document.Title.Substring(0, ArcMap.Application.Document.Title.Length - 4); //create new ArcPress printer classes docPrinter = new ArcPressPrinterClass(); docArcPressPrinter = new ArcPressPrinterClass(); try { //auto-select the driver based on the printer's name. docArcPressPrinter.AutoSelectDriverByName(ArcMap.ThisApplication.Paper.PrinterName); //if the printer cannot be auto-selected, exit. if (docArcPressPrinter.SelectedDriverId == null) { MessageBox.Show("Could not auto-select ArcPress driver for printer"); return; } //transfer the ArcPress printer properties into docPrinter docPrinter = (IPrinter)docArcPressPrinter; //the paper should be the same as the application's paper. docPrinter.Paper = ArcMap.ThisApplication.Paper; //make sure the paper orientation is set to the orientation matching the current view. docPrinter.Paper.Orientation = ArcMap.Document.PageLayout.Page.Orientation; //set the spool filename (this is the job name that shows up in the print queue) docPrinter.SpoolFileName = sNameRoot; // Find out how many printer pages the output will cover. iNumPages will always be 1 // unless the user explicitly sets the tiling options in the file->Print dialog. if (ArcMap.Document.ActiveView is IPageLayout) { ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, out iNumPages); } else { iNumPages = 1; } for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++) { //the StepProgressor is what creates the bar graph of the print's progress. docPrinter.StepProgressor = ArcMap.Application.StatusBar.ProgressBar; try { PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null); } catch { MessageBox.Show("Error printing page " + lCurrentPageNum); } } } catch { MessageBox.Show("Could not auto-select ArcPress driver for this printer"); } }
public void PrintActiveViewParameterized(int iResampleRatio) { /* Prints the Active View of the document to selected output format. */ // IActiveView docActiveView = ArcMap.Document.ActiveView; IPrinter docPrinter; IPrintAndExport PrintAndExport = new PrintAndExportClass(); IPaper docPaper; /* printdocument is from the .NET assembly system.drawing.printing */ System.Drawing.Printing.PrintDocument sysPrintDocumentDocument; short iNumPages; /* 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) { //Set docPaper's printername to the printername of the default printer docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName; } else { //if we get an unexpected result, return. MessageBox.Show("Error getting default printer info, exiting..."); return; } //make sure the paper orientation is set to the orientation matching the current view. docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation; /* 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. */ docPrinter.Paper = docPaper; //set the spoolfilename (this is the job name that shows up in the print queue) docPrinter.SpoolFileName = "PrintActiveViewSample"; // Find out how many printer pages the output will cover. if (ArcMap.Document.ActiveView is IPageLayout) { ArcMap.Document.PageLayout.Page.PrinterPageCount (docPrinter, 0, out iNumPages); } else { iNumPages = 1; } for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++) { try { PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null); } catch { //need to catch exceptions in PrintAndExport.Print - for instance if the job is cancelled. MessageBox.Show("An error has occurred."); } } }
public void PrintActiveViewParameterized(int iResampleRatio) { /* Prints the Active View of the document to selected output format. */ // IActiveView docActiveView = ArcMap.Document.ActiveView; IPrinter docPrinter; IPrintAndExport PrintAndExport = new PrintAndExportClass(); IPaper docPaper; /* printdocument is from the .NET assembly system.drawing.printing */ System.Drawing.Printing.PrintDocument sysPrintDocumentDocument; short iNumPages; /* 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) { //Set docPaper's printername to the printername of the default printer docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName; } else { //if we get an unexpected result, return. MessageBox.Show("Error getting default printer info, exiting..."); return; } //make sure the paper orientation is set to the orientation matching the current view. docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation; /* 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. */ docPrinter.Paper = docPaper; //set the spoolfilename (this is the job name that shows up in the print queue) docPrinter.SpoolFileName = "PrintActiveViewSample"; // Find out how many printer pages the output will cover. if (ArcMap.Document.ActiveView is IPageLayout) { ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, out iNumPages); } else { iNumPages = 1; } for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++) { try { PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null); } catch { //need to catch exceptions in PrintAndExport.Print - for instance if the job is cancelled. MessageBox.Show("An error has occurred."); } } }