LoginSignup
0
0

More than 3 years have passed since last update.

Java  PowerPointを印刷

Posted at

 

今日はSpire.Presentation for Java でPowerPointを印刷する方法を紹介します。主に二つの方法があります。すなわち:

  1. PresentationPrintDocument を利用することで
  2. PrinterSettingsを利用することで

というほうに行うことができます。

下準備

1.E-iceblueの公式サイトからFree Spire. Presentation for Java無料版をダウンロードしてください。

f:id:lendoris:20210203172902p:plain

2.IDEを起動して新規プロジェクトを作成してから、インストールされたファイルにあった相応しいSpire. Presentation.jarを参照に追加してください。

f:id:lendoris:20210203172915p:plain

 PresentationPrintDocument

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();

    }
}

PrinterSettings

import com.spire.ms.Printing.*;
import com.spire.presentation.*;
public class PrintPPT {

    public static void main(String[] args) throws Exception {

 //ファイルをロードします。
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //PrinterSettingsで印刷します。
        PrinterSettings ps = new PrinterSettings();
        ps.setPrintRange(PrintRange.AllPages);

        //ps.setPrintToFile(true);

        //印刷時に枠をつけます。
        presentation.setSlideFrameForPrint(true);

        //灰色にします
        presentation.setGrayLevelForPrint(true);


        presentation.setSlideCountPerPageForPrint(PageSlideCount.Four);

        //印刷の方法を設定します。
        presentation.setOrderForPrint(Order.Horizontal);

        //印刷したいスライドを選びます。 
        presentation.SelectSlidesForPrint("1", "3");

        //印刷します。
        presentation.print(ps);
        presentation.dispose();
    }
}

f:id:lendoris:20210203173035p:plain

 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0