2015-04-23 122 views
0

我目前正在爲我的僱主使用PDF渲染功能的C#應用​​程序。 Pdfium.Net在顯示PDF文件方面做得非常出色,但應用程序也必須能夠打印它們。有人知道通過這個API打印當前PDF文檔的方法嗎?我檢查了可能的地方,但我還沒有找到任何東西。在Pdfium .NET SDK中打印功能

+0

您是否在[patagames.com](patagames.com)詢問供應商? –

回答

1

要打印PDF文檔,可以使用標準的.Net框架,如在下面的代碼所示:

//.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(); 
+0

我真的很感激看到這個vb.net版本。我不知道如何將pd.PrintPage + =(s,e)=> {...}行轉換爲vb.net。謝謝 – nuander

+0

請看這裏:http://forum.patagames.com/posts/m271-Print-functionality-in-Pdfium--NET-SDK#post271 – Paul

0

其中.Render的()的變體允許你直接繪製到Graphics上下文切削在上面的例子中不需要中間位圖。