本文主要概括總結了常見的幾種PPT幻燈片文檔打印的方法及需求。具體經過C#示例來分別闡述如下幾種狀況:html
1、經過PresentationPrintDocument 對象來打印ide
2、經過PrinterSettings 對象來設置打印選項並打印工具
使用工具:Spire.Presentation for .NET網站
dll文件獲取及引用:spa
方法1:經過官網下載dll文件包。下載後,解壓文件並安裝。完成安裝後,將安裝路徑下BIN文件夾中的Spire.Presentation.dll程序集文件添加引用至C#程序。code
方法2:可經過Nuget網站下載。htm
C#代碼示例(供參考)對象
【示例1】經過默認打印機打印PPT全部頁面blog
Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); PresentationPrintDocument document = new PresentationPrintDocument(ppt); document.PrintController = new StandardPrintController(); ppt.Print(document);
【示例2】使用虛擬打印機(Microsoft XPS Document Writer)打印文檔
Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); PresentationPrintDocument document = new PresentationPrintDocument(ppt); document.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; ppt.Print(document);
【示例3】設置打印頁碼範圍、份數和打印時的顯示名稱
Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); PresentationPrintDocument document = new PresentationPrintDocument(ppt); //設置打印過程當中的顯示名稱 document.DocumentName = "展現報表部分打印"; //設置打印頁碼範圍 document.PrinterSettings.PrintRange = PrintRange.SomePages; document.PrinterSettings.FromPage = 1; document.PrinterSettings.ToPage = 2; //設置打印份數 document.PrinterSettings.Copies = 2; ppt.Print(document);
【示例4】經過PrinterSettings 對象來設置打印選項並打印
//加載示例文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); //使用 PrinterSettings 對象打印幻燈片 PrinterSettings ps = new PrinterSettings(); ps.PrintRange = PrintRange.AllPages; ps.PrintToFile = true; ps.PrintFileName = ("Print.xps"); //打印時幻燈片加框 ppt.SlideFrameForPrint = true; //灰度打印 ppt.GrayLevelForPrint = true; //每四張幻燈片打印到一頁 ppt.SlideCountPerPageForPrint = PageSlideCount.Four; //設置打印方向 ppt.OrderForPrint = Order.Horizontal; ////打印不連續頁面 //ppt.SelectSlidesForPrint("1", "3"); //打印 ppt.Print(ps);
(本文完)
轉載請註明出處!!