Knowledgebase (2300)
When a PowerPoint presentation is converted to PDF, its document layout and formatting are fixed. Recipients can view the converted document without having Microsoft PowerPoint to be installed, but they can not modify it easily. In this article, we will demonstrate how to convert PowerPoint presentations to PDF in Java using Spire.Presentation for Java library.
- Convert a Whole PowerPoint Presentation to PDF
- Convert Specific Slide of a PowerPoint Presentation to PDF
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml 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>10.11.4</version>
</dependency>
</dependencies>
Convert a Whole PowerPoint Presentation to PDF in Java
The following steps show you how to convert a whole PowerPoint presentation to PDF:
- Initialize an instance of Presentation class.
- Load the PowerPoint presentation using Presentation.loadFromFile() method.
- Save it to PDF using Presentation.saveToFile(filePath, FileFormat.PDF) method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class ConvertPowerPointToPDF {
public static void main(String []args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Save it as PDF
ppt.saveToFile("ToPdf1.pdf", FileFormat.PDF);
}
}

Convert Specific Slide of a PowerPoint Presentation to PDF in Java
The following steps show you how to convert a specific slide of a PowerPoint presentation to PDF:
- Initialize an instance of Presentation class.
- Load the PowerPoint presentation using Presentation.loadFromFile() method.
- Get the desired slide by its index using Presentation.getSlides().get(slideIndex) method.
- Save it to PDF using ISlide.saveToFile(filePath, FileFormat.PDF) method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class ConvertSlidesToPDF {
public static void main(String []args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a PowerPoint presentation
ppt.loadFromFile("Sample.pptx");
//Get the second slide
ISlide slide= ppt.getSlides().get(1);
//Save the slide to PDF
slide.saveToFile("ToPdf2.pdf", FileFormat.PDF);
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
This article demonstrates how to set the row height and column width of an existing table in a PowerPoint document using Spire.Presentation for Java.
Below is the screenshot of the input PowerPoint document:

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.ITable;
import com.spire.presentation.Presentation;
public class Table_Row_Height_and_Column_Width {
public static void main(String[] args) throws Exception {
//Load the PowerPoint document
Presentation ppt = new Presentation();
ppt.loadFromFile("Table.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Get the first table in the slide
ITable table = (ITable) slide.getShapes().get(0);
//Change the height of the first table row and the width of the first table column
table.getTableRows().get(0).setHeight(100);
table.getColumnsList().get(0).setWidth(250);
//Save the document
ppt.saveToFile("Output.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}
Output:

When you edit a PDF document, it is sometimes necessary to delete redundant pages of the document or add new pages to the document. This article will show you how to add or delete pages in a PDF document using Spire.PDF for Java.
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml 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.pdf</artifactId>
<version>11.11.11</version>
</dependency>
</dependencies>
Add Empty Pages to a PDF Document
The following steps show you how to add empty pages to a specific position of a PDF document and its end.
- Create a PdfDocument instance.
- Load a sample PDF document using PdfDocument.loadFromFile() method.
- Create a new blank page and insert it into a specific position of the document using PdfDocument.getPages().insert(int index) method.
- Create another new blank page with the specified size and margins and then append it to the end of the document using PdfDocument.getPages().add(java.awt.geom.Dimension2D size, PdfMargins margins) method.
- Save the document to another file using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
import com.spire.pdf.graphics.PdfMargins;
public class InsertEmptyPage {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a sample PDF document
pdf.loadFromFile("C:\\Users\\Test1\\Desktop\\sample.pdf");
//Insert a blank page to the document as the second page
pdf.getPages().insert(1);
//Add an empty page to the end of the document
pdf.getPages().add(PdfPageSize.A4, new PdfMargins(0, 0));
//Save the document to another file
pdf.saveToFile("output/insertEmptyPage.pdf");
pdf.close();
}
}

Delete an Existing Page in a PDF Document
The following steps are to delete a specific page of a PDF document.
- Create a PdfDocument instance.
- Load a sample PDF document using PdfDocument.loadFromFile() method.
- Remove a specific page of the document using PdfDocument.getPages().removeAt(int index) method.
- Save the document to another file using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class DeletePage {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a sample PDF document
pdf.loadFromFile("C:\\Users\\Test1\\Desktop\\sample.pdf");
//Delete the second page of the document
pdf.getPages().removeAt(1);
//Save the document to another file
pdf.saveToFile("output/deletePage.pdf");
pdf.close();
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.