Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1280173
  • 博文数量: 135
  • 博客积分: 10588
  • 博客等级: 上将
  • 技术积分: 1325
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-18 11:12
文章分类

全部博文(135)

文章存档

2013年(6)

2012年(3)

2011年(11)

2010年(7)

2009年(14)

2008年(6)

2007年(42)

2006年(46)

分类: 嵌入式

2010-08-01 13:45:52

private void PrintAuto(IActiveView pActiveView)
{

    IPaper pPaper = new Paper();
    IPrinter pPrinter = new EmfPrinterClass();

    System.Drawing.Printing.PrintDocument sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument();

    pPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName;
    pPrinter.Paper = pPaper;

    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 userRECT = pActiveView.ExportFrame;

    userRECT.left = (int)(pPrinter.PrintableBounds.XMin * Resolution);
    userRECT.top = (int)(pPrinter.PrintableBounds.YMin * Resolution);

    if ((w / h) > (pw / ph))//以宽度来调整高度
    {

        userRECT.right = userRECT.left + (int)(pPrinter.PrintableBounds.Width * Resolution);
        userRECT.bottom = userRECT.top + (int)((pPrinter.PrintableBounds.Width * Resolution) * h / w);
    }
    else
    {
        userRECT.bottom = userRECT.top + (int)(pPrinter.PrintableBounds.Height * Resolution);
        userRECT.right = userRECT.left + (int)(pPrinter.PrintableBounds.Height * Resolution * w / h);

    }

    IEnvelope pDriverBounds = new EnvelopeClass();
    pDriverBounds.PutCoords(userRECT.left, userRECT.top, userRECT.right, userRECT.bottom);

    ITrackCancel pCancel = new CancelTrackerClass();
    int hdc = pPrinter.StartPrinting(pDriverBounds, 0);

    pActiveView.Output(hdc, pPrinter.Resolution,
    ref userRECT, pActiveView.Extent, pCancel);

    pPrinter.FinishPrinting();

}


调用
PrintAuto(this.axMapControl1.ActiveView);

if ($ != jQuery) { $ = jQuery.noConflict(); }
阅读(2242) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~