C# 打印PDF文件

在写这个标题的时候,我的心情是极度崩溃的,连续奋战N久之后,才把这个问题搞定,记录下吧!
首先找到
O2S.Components.PDFView4NET.dll
O2S.Components.PDFRender4NET.dll
FontBox-0.1.0-dev.dll
IKVM.GNU.Classpath.dll
IKVM.Runtime.dll
PDFBox-0.7.3.dll
这6个DLL找到之后才写后面的代码
这是引用的3个命名空间
using O2S.Components.PDFRender4NET;
using System.Drawing.Printing;
using O2S.Components.PDFRender4NET.Printing;

        /// <summary>
        /// 打印的代码
        /// </summary>
        /// <param name="url">要打印的PDF路径</param>
        private void printShow(string url)
        {
            PDFFile file = PDFFile.Open(url);
            PrinterSettings settings = new PrinterSettings();
            System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
            settings.PrinterName = 打印机的名字;
            settings.PrintToFile = false;

            //设置纸张大小(可以不设置取,取默认设置)3.90 in,  8.65 in
            PaperSize ps = new PaperSize("Your Paper Name", config.Width, config.Height);
            ps.RawKind = 150; //如果是自定义纸张,就要大于118,(A4值为9,详细纸张类型与值的对照请看http://msdn.microsoft.com/zh-tw/library/system.drawing.printing.papersize.rawkind(v=vs.85).aspx)

            O2S.Components.PDFRender4NET.Printing.PDFPrintSettings pdfPrintSettings = new O2S.Components.PDFRender4NET.Printing.PDFPrintSettings(settings);
            pdfPrintSettings.PaperSize = ps;
            pdfPrintSettings.PageScaling = O2S.Components.PDFRender4NET.Printing.PageScaling.FitToPrinterMarginsProportional;
            pdfPrintSettings.PrinterSettings.Copies = 2;

            file.Print(pdfPrintSettings);
            file.Dispose();
        }

你可能感兴趣的:(C# 打印PDF文件)