C#利用PdfiumViewer组件直接打印PDF文件

测试环境:net4.8

使用PdfiumViewer组件来打印,需要在nuget安装安装三个包:

1.PdfiumViewer

2.PdfiumViewer.Native.x86.v8 – xfa

3.PdfiumViewer.Native.x86_64.v8 – xfa

string pdfFilePath = @"C:\a.pdf"; // PDF文件路径
PrintPDF(pdfFilePath, m_PrinterName);     //m_PrinterName 打印机名称

public static void PrintPDF(string pdfFilePath, string m_PrinterName)
        {

            using (var document = PdfiumViewer.PdfDocument.Load(pdfFilePath))
            {
                using (var printDocument = document.CreatePrintDocument())
                {
                    // check the current default printer
                    //System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();
                    //string defaultPrinterName = settings.PrinterName;

                    //printDocument.OriginAtMargins = true;
                    //printDocument.PrinterSettings.PrintFileName = "123";
                    //printDocument.PrinterSettings.Copies = numCopies;
                    //printDocument.PrintController = new System.Drawing.Printing.StandardPrintController();
                    printDocument.PrinterSettings.PrinterName = m_PrinterName;   //指定打印机名称
                    //printDocument.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("customsize", 100, 150);
                    printDocument.DefaultPageSettings.Landscape = false;  //纵打
                    printDocument.Print();

                }
            }
        }

 

来源地址:C#利用PdfiumViewer组件直接打印PDF文件

转载声明:本站文章若无特别说明,皆为原创,转载请注明来源:www.88531.cn资享网,谢谢!^^

© 版权声明
THE END
喜欢就支持一下吧
点赞33 分享