Spire.PDF(點擊下載)是一個專業的PDF組件,可以獨立地建立、編寫、編輯、操做和閱讀PDF文件,支持 .NET、Java、WPF和Silverlight。Spire.PDF的PDF API擁有豐富的功能,如安全設置(包括數字簽名)、PDF文本/附件/圖片提取、PDF文件合併/拆分、元數據更新、章節和段落優化、圖形/圖像描繪和插入、表格建立和處理、數據導入等等。安全
本文將介紹如下幾種常見方式:優化
使用默認打印機打印PDF文檔spa
使用虛擬打印機(Microsoft XPS Document Writer)打印PDF文檔圖片
指定打印機及PDF文檔打印頁碼範圍文檔
靜默打印PDF文檔it
雙面打印PDF文檔pdf
使用默認打印機下載
//加載PDF文檔 PdfDocument doc = new PdfDocument(); doc.LoadFromFile("Test.pdf"); //使用默認打印機打印文檔全部頁面 doc.PrintDocument.Print();
使用虛擬打印機(Microsoft XPS Document Writer)im
//加載PDF文檔 PdfDocument doc = new PdfDocument(); doc.LoadFromFile("Test.pdf"); //選擇Microsoft XPS Document Writer打印機 doc.PrintDocument.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; //打印PDF文檔到XPS格式 doc.PrintDocument.PrinterSettings.PrintToFile = true; doc.PrintDocument.PrinterSettings.PrintFileName = "PrintToXps.xps"; doc.PrintDocument.Print();
指定打印機及文檔打印頁碼範圍數據
//加載PDF文檔 PdfDocument doc = new PdfDocument(); doc.LoadFromFile("Test.pdf"); //設置打印對話框屬性 PrintDialog dialogPrint = new PrintDialog(); dialogPrint.AllowPrintToFile = true; dialogPrint.AllowSomePages = true; dialogPrint.PrinterSettings.MinimumPage = 1; dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count; dialogPrint.PrinterSettings.FromPage = 1; dialogPrint.PrinterSettings.ToPage = doc.Pages.Count; if (dialogPrint.ShowDialog() == DialogResult.OK) { //指定打印機及打印頁碼範圍 doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage; doc.PrintToPage = dialogPrint.PrinterSettings.ToPage; doc.PrinterName = dialogPrint.PrinterSettings.PrinterName; //打印文檔 PrintDocument printDoc = doc.PrintDocument; dialogPrint.Document = printDoc; printDoc.Print(); }
靜默打印
//加載PDF文檔 var doc = new PdfDocument(); doc.LoadFromFile("Test.pdf"); //靜默打印PDF文檔 PrintDocument printDoc = doc.PrintDocument; printDoc.PrintController = new StandardPrintController(); printDoc.Print();
雙面打印
//加載PDF文檔 PdfDocument doc = new PdfDocument(); doc.LoadFromFile("Test.pdf"); //判斷打印機是否支持雙面打印 bool isDuplex = doc.PrintDocument.PrinterSettings.CanDuplex; if (isDuplex) { //若是支持則設置雙面打印模式,可選:Default/Simplex/Horizontal/Vertical doc.PrintDocument.PrinterSettings.Duplex = Duplex.Default; //打印文檔 doc.PrintDocument.Print(); }