C#打印PDF文件

发布时间:2020-06-02编辑:佚名阅读(2485)

需要引用O2S.Components.PDFRender4NET.dll

using O2S.Components.PDFRender4NET;
  
        /// <summary>
         /// 打印的代码
         /// </summary>
         /// <param name="url">要打印的PDF路径</param>
         private int  printShow(string url)
         {
             int isOK = 0;
             PDFFile file = PDFFile.Open(url);
             PrinterSettings settings = new PrinterSettings();
             settings.PrinterName = "hp LaserJet 1160 PCL 5e";
             settings.PrintToFile = false ;
  
            //设置纸张大小(可以不设置,取默认设置)3.90 in,  8.65 in
             PaperSize ps = new PaperSize("test",4,9);
             ps.RawKind = 9; //如果是自定义纸张,就要大于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 = 1;
  
            try
             {
                 file.Print(pdfPrintSettings);
                 isOK = 1;
             }
             catch (Exception)
             {
                 isOK = -1;
                 throw;
             }
             finally
             {
  
                file.Dispose();
             }
             return isOK;
         }


    关键字: C# 打印PDF文件


鼓掌

0

正能量

1

0

呵呵

0


评论区