继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

C# 打印PPT幻灯片

Eiceblue
关注TA
已关注
手记 107
粉丝 9
获赞 48

本文主要归纳总结了常见的几种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);


(本文完)

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP