Spire.Pdf打印PDF文件

 1      /// <summary>
 2         /// Spire.Pdf打印PDF文件
 3         /// </summary>
 4         /// <param name="fileName">包含文件路径的文件名称</param>
 5         /// <returns></returns>
 6         private int PrintPDF(string fileName)
 7         {
 8             int result=0;
 9             try
10             {
11                 using (PdfDocument pd = new PdfDocument())
12                 {
13                     //加载一个文档
14                     pd.LoadFromFile(fileName);
15                     //设置完成打印时的触发事件
16                     //pd.PrintDocument.EndPrint += new PrintEventHandler();
17                     //设置纸张规格
18                     PrintDocument printDocument = new PrintDocument();
19                     foreach (PaperSize ps in printDocument.PrinterSettings.PaperSizes)
20                     {
21                         if (ps.PaperName == "A4")
22                             pd.PrintDocument.DefaultPageSettings.PaperSize = ps;
23                     }
24                     //指定打印机名称
25                     pd.PrinterName = "PrinterName";
26                     //设置为纵向打印
27                     pd.PrintDocument.DefaultPageSettings.Landscape = false;
28                     //设置为静默打印
29                     pd.PrintDocument.PrintController = new StandardPrintController();
30                     //执行打印
31                     pd.PrintDocument.Print();
32                 }
33                 return result;
34             }
35             catch (Exception ex)
36             {
37 
38                 throw;
39                 return result = -1;
40             }
41         }

 

上一篇:使用svn从恢复到某个版本的时候会报错


下一篇:深度学习词汇 Developing Our Own Deep Learning Toolset