1 ///
2 /// Spire.Pdf打印PDF文件
3 ///
4 /// 包含文件路径的文件名称
5 ///
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 }