public void PrintAuto(IActiveView pActiveView, string Pmapname)
{
try
{
PrintDialog printDialog = new PrintDialog();
printDialog.AllowSomePages = true;
printDialog.ShowHelp = true;
printDialog.ShowNetwork = true;
printDialog.AllowCurrentPage = true;
printDialog.AllowPrintToFile = true;
printDialog.AllowSelection = true;
printDialog.PrintToFile = true;
System.Drawing.Printing.PrintDocument pPrintDocument = new System.Drawing.Printing.PrintDocument();
printDialog.Document = pPrintDocument;
DialogResult result = printDialog.ShowDialog();
if (result == DialogResult.OK)
{
IPaper pPaper = new Paper();
IPrinter pPrinter = new EmfPrinterClass();
pPaper.PrinterName = pPrintDocument.PrinterSettings.PrinterName;
pPrinter.Paper = pPaper;
pPrinter.SpoolFileName = Pmapname;
int Resolution = pPrinter.Resolution;
double W, H;
IEnvelope pEnvelope = pActiveView.Extent;
W = pEnvelope.Width;
H = pEnvelope.Height;
double PW, PH;
pPrinter.QueryPaperSize(out PW, out PH);
tagRECT usertagRECT = pActiveView.ExportFrame;
usertagRECT.left = (int)(pPrinter.PrintableBounds.XMin * Resolution);
usertagRECT.top = (int)(pPrinter.PrintableBounds.YMin * Resolution);
if ((W / H) > (PW / PH))
{
usertagRECT.right = usertagRECT.left + (int)(pPrinter.PrintableBounds.Width * Resolution);
usertagRECT.bottom = usertagRECT.top + (int)((pPrinter.PrintableBounds.Width * Resolution) * H / W);
}
else
{
usertagRECT.right = usertagRECT.left + (int)(pPrinter.PrintableBounds.Height * Resolution);
usertagRECT.bottom = usertagRECT.top + (int)((pPrinter.PrintableBounds.Height * Resolution) * H / W);
}
IEnvelope pDriverBounds = new EnvelopeClass();
pDriverBounds.PutCoords(usertagRECT.left, usertagRECT.top, usertagRECT.right, usertagRECT.bottom);
ITrackCancel pTrackCancel = new CancelTrackerClass();
int hdc = pPrinter.StartPrinting(pDriverBounds, 0);
pActiveView.Output(hdc, pPrinter.Resolution, ref usertagRECT, pActiveView.Extent, pTrackCancel);
pPrinter.FinishPrinting();
}
else
{
return;
}
}
catch (Exception ex)
{
Class_Log4Net.WriteError("Class_Print类中PrintAuto()" + ex.Message + ex.Source);
}
}