zoukankan      html  css  js  c++  java
  • 根据第三方库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文件:https://files.cnblogs.com/files/andies/NET4.0.zip

  • 相关阅读:
    递归算法介绍及Java应用实战
    常用缓存淘汰算法(LFU、LRU、ARC、FIFO、MRU)
    阿里巴巴高级Java面试题(首发,70道)
    2017阿里技术年度精选(全)
    10年老兵给程序员的10条建议!
    8条关于Web前端性能的优化建议
    (16)约束
    (15)oracle序列
    (14)oracle数据字典
    (13)oracle导出、导入
  • 原文地址:https://www.cnblogs.com/andies/p/5319622.html
Copyright © 2011-2022 走看看