马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

C# 打印PPT幻灯片

[复制链接]
查看2269 | 回复0 | 2019-9-26 09:22:02 | 显示全部楼层 |阅读模式

本文告急归纳总结了常见的几种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全部页面

  1. Presentation ppt = new Presentation();
  2. ppt.LoadFromFile("Sample.pptx");
  3. PresentationPrintDocument document = new PresentationPrintDocument(ppt);
  4. document.PrintController = new StandardPrintController();
  5. ppt.Print(document);
复制代码

【示例2】利用虚拟打印机(Microsoft XPS Document Writer)打印

  1. Presentation ppt = new Presentation();
  2. ppt.LoadFromFile("Sample.pptx");
  3. PresentationPrintDocument document = new PresentationPrintDocument(ppt);
  4. document.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
  5. ppt.Print(document);
复制代码

【示例3】设置打印页码范围、份数和打印时的显示名称

  1. Presentation ppt = new Presentation();
  2. ppt.LoadFromFile("Sample.pptx");
  3. PresentationPrintDocument document = new PresentationPrintDocument(ppt);
  4. //设置打印过程中的显示名称
  5. document.DocumentName = "展示报表部分打印";
  6. //设置打印页码范围
  7. document.PrinterSettings.PrintRange = PrintRange.SomePages;
  8. document.PrinterSettings.FromPage = 1;
  9. document.PrinterSettings.ToPage = 2;
  10. //设置打印份数
  11. document.PrinterSettings.Copies = 2;
  12. ppt.Print(document);
复制代码

【示例4】通过PrinterSettings 对象来设置打印选项并打印

  1. //加载示例文档
  2. Presentation ppt = new Presentation();
  3. ppt.LoadFromFile("Sample.pptx");
  4. //利用 PrinterSettings 对象打印幻灯片
  5. PrinterSettings ps = new PrinterSettings();
  6. ps.PrintRange = PrintRange.AllPages;
  7. ps.PrintToFile = true;
  8. ps.PrintFileName = ("Print.xps");
  9. //打印时幻灯片加框
  10. ppt.SlideFrameForPrint = true;
  11. //灰度打印
  12. ppt.GrayLevelForPrint = true;
  13. //每四张幻灯片打印到一页
  14. ppt.SlideCountPerPageForPrint = PageSlideCount.Four;
  15. //设置打印方向
  16. ppt.OrderForPrint = Order.Horizontal;
  17. ////打印不连续页面
  18. //ppt.SelectSlidesForPrint("1", "3");
  19. //打印
  20. ppt.Print(ps);
复制代码

(本文完)

转载请注明出处!!







来源:https://www.cnblogs.com/Yesi/archive/2019/09/24/11578274.html
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则