【问题标题】:Writing a GridView to print doc in PrintPageEventArgs (PrintDocument在 PrintPageEventArgs (PrintDocument
【发布时间】:2011-03-15 20:31:47
【问题描述】:

我目前正在用 ASP.NET/C# 编写一个应用程序,用户需要能够通过基于 Web 的管理系统生成 PDF 格式的发票摘要。

客户不想使用 iTextSharp 之类的开源解决方案(我知道这很愚蠢),而是购买了带有虚拟 PDF 打印机的 Adob​​e Acrobat/Reader(不确定哪个)。因此,我们将与服务器上的这台打印机进行交互以生成 PDF。

效果很好 - 我们可以轻松生成 PDF 并将其显示给用户。但是,现在将内容写入要打印的文档的方式(使用 PrintPageEventArgs 事件的 Graphics 类)对我来说有点陌生。编写文本和标题信息是小菜一碟,但是将 GridView 的内容写入文档最简单的方法是什么?

这是我正在使用的那种东西的一些示例代码:

   protected void Page_Load(object sender, EventArgs e)
        {
            PrintDocument NewDoc = new PrintDocument();
            NewDoc.PrinterSettings.PrinterName = "PrinterName";
            NewDoc.PrintPage += new PrintPageEventHandler(NewDoc_PrintPage);
            NewDoc.Print();
        }

        void NewDoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawString("Test Header", new Font("Verdana", 18), Brushes.Black, 220, 120);
    }

【问题讨论】:

    标签: c# asp.net pdf printdocument


    【解决方案1】:

    最终不得不自己绘制网格。非常 hacky,但它确实有效。

    【讨论】:

      猜你喜欢
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 2014-04-30
      • 2011-03-30
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多