根据第三方库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

转载于:https://www.cnblogs.com/andies/p/5319622.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值