根據第三方庫spire.pdf使用指定打印機打印pdf文件


 private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument doc = new PdfDocument();
            string filePath = "D:\\用戶目錄\\我的文檔\\output2.pdf";
            doc.LoadFromFile(filePath);
            doc.PrinterName = "HP LaserJet M1522 MFP Series PCL 6";
            doc.PrintDocument.Print();
        
         }

打印輸出都是pdf本身的頁面設置。以下代碼時輸出打印機默認的頁面設置:

 1.創建PrintDocument組件的對象,

 2.PrintDialog設置對文檔進行打印的打印機的參數,對話框的屬性Document為指定的PrintDocument類對象,修改的設置將保存到PrintDocument組件對象中.

 3.調用PrintDocument.Print方法來實際打印文檔.

 

  private void button1_Click(object sender, EventArgs e)
        {
         
            PdfDocument doc = new PdfDocument();
            string filePath = "D:\\用戶目錄\\我的文檔\\output2.pdf";
            string printername = "HP Universal Printing PCL 6";
            doc.LoadFromFile(filePath);
            PrintDocument(doc, printername);

        }
        private void PrintDocument(PdfDocument doc, string printername)
        {
            PrintDialog dialogPrint = new PrintDialog();
          
            doc.PrinterName = printername;
            doc.PageScaling = PdfPrintPageScaling.ActualSize; 
            //PrintDocument類是實現打印功能的核心,它封裝了打印有關的屬性、事件、和方法
            PrintDocument printDoc = doc.PrintDocument;

            // 獲取PrinterSettings類的PrintDocument對象
            dialogPrint.Document = printDoc;
            
            printDoc.Print();

             
        }

 

參考: http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Document-Operation/How-to-print-PDF-files-in-C.html

         http://www.torres.at/pdf-printing-net/

相關dll文件:http://files.cnblogs.com/files/andies/NET4.0.zip


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM