设为首页 加入收藏

TOP

C# 打印PPT幻灯片
2019-09-24 18:11:08 】 浏览:39
Tags:打印 PPT 幻灯片

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

 

(本文完)

转载请注明出处!!

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C#工作常用关键字 下一篇装箱和拆箱-值类型和引用类型的区..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目