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

  • 相关阅读:
    2017 ACM-ICPC西安网赛B-Coin
    Codeforces389D(SummerTrainingDay01-J)
    Codeforces672D(SummerTrainingDay01-I)
    VS2017.滚动条选项
    VS.自动调试
    ffmpeg.mp4.格式资料
    vs2017.unresolved external symbol __imp__fprintf&__imp____iob_func
    vs2017."const char *"的实参与"char *"的形参不兼容_goto跳过类型声明
    vue项目开发时怎么解决跨域
    vue奇怪的知识点又增加了
  • 原文地址:https://www.cnblogs.com/andies/p/5319622.html
Copyright © 2011-2022 走看看