【问题标题】:Print functionality in Pdfium .NET SDKPdfium .NET SDK 中的打印功能
【发布时间】:2015-07-01 10:01:38
【问题描述】:

我目前正在为我的雇主开发一个使用 PDF 呈现功能的 C# 应用程序。 Pdfium.Net 在显示 PDF 方面做得很好,但应用程序也必须能够打印它们。有人知道通过此 API 打印当前 PDF 文档的方法吗?我已经检查了可能的地方,但没有找到任何东西。

【问题讨论】:

  • 你问过 [patagames.com](patagames.com) 的供应商吗?

标签: c# .net api pdf printing


【解决方案1】:

.Render() 变体之一允许您直接在 Graphics 上下文上绘制,从而无需上例中的中间位图。

【讨论】:

    【解决方案2】:

    要打印PDF文档,可以使用标准的.Net Framework,如下代码所示:

    //.Net Framework class from System.Drawing.Printing namespace
    PrintDocument pd = new PrintDocument();
    int pageForPrint = 0;
    
    pd.PrintPage += (s, e) =>
    {
        using (PdfBitmap bmp = new PdfBitmap((int)e.PageSettings.PrintableArea.Width, (int)e.PageSettings.PrintableArea.Height, true))
        {
            //Render to PdfBitmap using page's Render method with FPDF_PRINTING flag
            pdfView1.Document.Pages[pageForPrint].Render
                (bmp,
                0,
                0,
                (int)e.PageSettings.PrintableArea.Width,
                (int)e.PageBounds.Height,
                Patagames.Pdf.Enums.PageRotate.Normal, Patagames.Pdf.Enums.RenderFlags.FPDF_PRINTING);
    
            //Draw rendered image to printer's graphics surface
            e.Graphics.DrawImageUnscaled(bmp.Image,
                (int)e.PageSettings.PrintableArea.X,
                (int)e.PageSettings.PrintableArea.Y);
    
            //Print next page
            if(pageForPrint< pdfView1.Document.Pages.Count)
            {
                pageForPrint++;
                e.HasMorePages = true;
            }
        }
    };
    
    //start printing routine
    pd.Print();
    

    【讨论】:

    • 我真的很高兴看到这个的 vb.net 版本。我不知道如何将 pd.PrintPage += (s, e) => { ... } 行转换为 vb.net。谢谢
    猜你喜欢
    • 2013-10-21
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 2014-11-29
    • 2022-01-01
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多