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

  • 相关阅读:
    一个web应用的诞生(4)
    一个web应用的诞生(7)
    一个web应用的诞生(6)
    HTTP状态码大全(转自wiki)
    十分钟搞懂什么是CGI
    HTTP真的很简单
    QT程序在发布的时候应注意的地方
    QT中获取选中的radioButton的两种方法
    WinEdit编辑器中中文乱码
    C++ lstrlen()
  • 原文地址:https://www.cnblogs.com/andies/p/5319622.html
Copyright © 2011-2022 走看看