本文主要归纳总结了常见的几种PPT幻灯片文档打印的方法及需求。具体通过C#示例来分别阐述以下几种情况:
一、通过PresentationPrintDocument 对象来打印
使用默认打印机打印文档
使用虚拟打印机(Microsoft XPS Document Writer)打印
设置打印页码范围、份数和打印PPT时的显示名称
二、通过PrinterSettings 对象来设置打印选项并打印
指定幻灯片打印页面
设置打印方向
设置纸张页面打印的幻灯片数量
设置灰度打印
设置幻灯片加框打印
使用工具:Spire.Presentation for .NET
dll文件获取及引用:
方法1:通过官网下载dll文件包。下载后,解压文件并安装。完成安装后,将安装路径下BIN文件夹中的Spire.Presentation.dll程序集文件添加引用至C#程序。
方法2:可通过Nuget网站下载。
C#代码示例(供参考)
【示例1】通过默认打印机打印PPT所有页面
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);(本文完)
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦