Tuesday, 25 January 2022

Print PowerPoint Documents in Java

PowerPoint presentations are often shared on a projector or display, but sometimes you might need a physical copy to share with your audience. This article will show you how to programmatically print all slides or some slides using Java codes.

DEPENDENCY

In order to realize the operation mentioned above, you’re required to download the package of Free Spire.Presentation for Java from this link, and then manually add Spire.Presentation.jar to your Java program. Or you can create a Maven project, and type the following codes in the pom.xml file to easily add the JAR file.

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>

Print All Slides of a PowerPoint Document

Free Spire.Presentation for Java supports printing all slides of a PowerPoint document using the PresentationPrintDocument.print() method. The following are detailed steps.

l  Create a Presentation instance.

l  Load a sample PowerPoint document using Presentation.loadFromFile() method.

l  Create a PresentationPrintDocument instance.

l  Print all slides of the document using PresentationPrintDocument.print() method.

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

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

//Create a Presentation instance
Presentation presentation = new Presentation();
//Load a sample PowerPoint document
presentation.loadFromFile("Sample.pptx");

//Print all slides of the document with the default printer
PresentationPrintDocument document = new PresentationPrintDocument(presentation);
document.print();
presentation.dispose();
}
}

Print All Slides of a PowerPoint Document

Free Spire.Presentation for Java supports printing all slides of a PowerPoint document using the PresentationPrintDocument.print() method. The following are detailed steps.

l  Create a Presentation instance.

l  Load a sample PowerPoint document using Presentation.loadFromFile() method.

l  Create a PresentationPrintDocument instance.

l  Print all slides of the document using PresentationPrintDocument.print() method.

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

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

//Create a Presentation instance
Presentation presentation = new Presentation();
//Load a sample PowerPoint document
presentation.loadFromFile("Sample.pptx");

//Select some slides of the document to print
PresentationPrintDocument document = new PresentationPrintDocument(presentation);
document.selectSlidesForPrint("2-4");
document.print();
presentation.dispose();
}
}


No comments:

Post a Comment

Change PDF Versions in Java

In daily work, you might need to change the version of a PDF document you have in order to ensure compatibility with another version which a...