zoukankan      html  css  js  c++  java
  • C# 打印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);

    (本文完)

    转载请注明出处!!

  • 相关阅读:
    ubuntu下安装jupyter notebook问题。ERROR: Package ‘ipython‘ requires a different Python: 3.5.2 not in 」=3.6
    VmWare虚拟机设置ubuntu和windows之间的共享文件夹
    标准测试宏选项
    C库函数、系统函数等调用错误的处理方法
    比atoi()函数更健壮的一类包装函数
    系统函数和C库函数调用的几种错误处理方法
    经典生产者-消费者问题解析
    linux下的并发编程详解
    一文学会GDB操作命令
    Stm32CubeMx lwip+freeRTOS TCP 服务
  • 原文地址:https://www.cnblogs.com/Yesi/p/11578274.html
Copyright © 2011-2022 走看看