Java 打印PPT幻灯片

本篇文章将介绍通过Java程序打印PPT幻灯片的方法。包括打印幻灯片的所有页、打印幻灯片中的指定页面。

使用工具:Free Spire.Presentation for Java (免费版)

 

Jar文件获取及导入:

方法1:通过官网下载jar文件包。下载后,解压文件,并将lib文件夹下的Spire.Presentation.jar文件导入java程序。

方法2可通过maven仓库安装导入。可参考导入方法

 

Java示例代码

【示例1】静默打印PPT所有页面

import com.spire.presentation.Presentation;
import com.spire.presentation.PresentationPrintDocument;

public class PrintPPT {
    public static void main(String[] args) throws Exception {
    String inputFile = "Sample.pptx";

    //加载文档
    Presentation presentation = new Presentation();
    presentation.loadFromFile(inputFile);

    //使用默认打印机打印所有文档中的所有幻灯片
    PresentationPrintDocument document = new PresentationPrintDocument(presentation);
    document.print();
    presentation.dispose();

    }
}

【示例2】不连续打印部分幻灯片

import com.spire.presentation.Presentation;
import com.spire.presentation.PresentationPrintDocument;

public class PrintPPT {
    public static void main(String[] args) throws Exception {
        String inputFile = "Sample.pptx";

        //加载文档
        Presentation presentation = new Presentation();
        presentation.loadFromFile(inputFile);
        
        PresentationPrintDocument document = new PresentationPrintDocument(presentation);

        //选择需要打印的幻灯片
        document.selectSlidesForPrint("1", "2-6");
        document.print();
        presentation.dispose();

        }
    }

(本文完)

猜你喜欢

转载自www.iteye.com/blog/miaonly-2443902