今日はSpire.Presentation for Java でPowerPointを印刷する方法を紹介します。主に二つの方法があります。すなわち:
- PresentationPrintDocument を利用することで
- PrinterSettingsを利用することで
というほうに行うことができます。
下準備
1.E-iceblueの公式サイトからFree Spire. Presentation for Java無料版をダウンロードしてください。
2.IDEを起動して新規プロジェクトを作成してから、インストールされたファイルにあった相応しいSpire. Presentation.jarを参照に追加してください。
PresentationPrintDocument
```JAVA 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();
}
}
<h4><strong>PrinterSettings</strong></h4>
```JAVA
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();
}
}