As PDF is the popular portable document format, so there comes the need to convert documents of other formats to PDF. Today, we will see different ways to convert PPT, PPTX, or ODP presentations to PDF in Java. In an earlier post, we have seen how to convert presentations using C#. The following scenarios will be covered in this article:
- Presentation Conversion Java API
- Convert PPT, PPTX, or ODP Presentations to PDF in Java
- Convert Specific Slides of Presentation to PDF
- Converting Consecutive Slides of Presentation to PDF
- Convert Password Protected Presentation to PDF
Presentation Conversion Java API
For the conversion of presentations to PDF format, I will be using GroupDocs.Conversion for Java in the examples of this article. Along with this feature, the API supports a long list of file formats to convert into one another in Java. These include converting eBooks, word-processing documents, spreadsheets, images, web-pages, emails, CAD, and many other document formats.
Download or Configure
Download the JAR from downloads or in the case of the Maven-based Java application, add the following repository and dependency configurations in the pom.xml.
<repository> <id>GroupDocsJavaAPI</id> <name>GroupDocs Java API</name> <url>http://repository.groupdocs.com/repo/</url> </repository>
<dependency> <groupId>com.groupdocs</groupId> <artifactId>groupdocs-conversion</artifactId> <version>21.1</version> </dependency>
Convert PPT, PPTX, or ODP Presentations to PDF in Java
Once the library is configured in your project, you now have various options to convert your presentations into portable PDF format. Let start with the simplest and quickest way to convert the whole presentation file.
- Create Converter class object with the source document.
- Instantiate PdfConvertOptions object.
- Call convert method of Converter class. Pass the output file path and the created PdfConvertOptions.
Here is the 3 liner Java code that converts the PowerPoint PPTX presentation file into PDF.
Similarly, you can convert the presentations of Microsoft PowerPoint PPT format or OpenOffice Impress ODP format to PDF with the same examples of this article.
Convert Specific Slides of Presentation to PDF in Java
If you want to skip few slides from the presentation, or just want to convert some specific slides to PDF instead of converting the whole presentation, setPages is the method you are searching for.
The below code converts the selected pages of the PPTX presentation to PDF in Java.
Convert Consecutive Slides of Presentation to PDF in Java
You can also select the specific set of slides in sequence to get them converted into PDF. Just mention the starting slide number, and then the number of slides in the sequence ahead.
- Start with initialization of Converter object with the presentation file.
- Set starting page number.
- Set number of consecutive pages.
- Convert slides to PDF using the convert method.
Here is the Java code showing the above steps and converting 3 consecutive slides of a PPTX presentation into PDF starting from the 2nd slide.
Convert Password Protected Presentation to PDF in Java
There are many load options while loading any presentation. You can provide the password for the protected presentation using setPassword method. After loading the presentation with the password, you can convert it just like any other presentation we converted before.
The following code converts a password protected PPTX presentation to PDF in Java after providing the password while loading.
Further, you can set the following load options:
- Specify the presentation format, however, it is auto-detected.
- Show or hide the comments.
- Show or hide hidden slides.
- Specify the substitute font for the missing fonts.
After trying the above examples, you must be confident to programmatically convert presentations and slides to PDF in your Java applications. You can try to build your own application using the above-highlighted features for MS PowerPoint and OpenOffice Impress presentation formats like PPT, PPTX, ODP, etc.