Java (482)
Merging cells involves combining adjacent cells into a larger one. This allows users to create the title cells that span multiple columns or rows, providing greater design flexibility. On the other hand, splitting cells means dividing a cell into several smaller ones, which is useful for creating detailed layouts or accommodating diverse content. In PowerPoint, users can merge and split table cells to adjust the structure and layout of tables. In this article, we will show you how to merge and split table cells in PowerPoint programmatically by using Spire.Presentation for Java.
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>11.3.5</version>
</dependency>
</dependencies>
Merge Table Cells in PowerPoint
Spire.Presentation for Java provides users with ITable.get(int columnIndex, int rowIndex) and ITable.mergeCells(Cell startCell, Cell endCell, boolean allowSplitting) methods to get and merge the specific cells. The detailed steps are as follows.
- Create an object of Presentation class.
- Load a sample file using Presentation.loadFromFile() method.
- Declare ITable variable.
- Get the table from the first slide by looping through all shapes.
- Get the specific cells by using ITable.get(int columnIndex, int rowIndex) method and merge them by using ITable.mergeCells(Cell startCell, Cell endCell, boolean allowSplitting) method.
- Save the result file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ITable;
import com.spire.presentation.Presentation;
public class MergeCells {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a sample PowerPoint file
presentation.loadFromFile("sample.pptx");
//Declare ITable variable
ITable table = null;
//Get the table from the first slide by looping through all shapes
for (Object shape : presentation.getSlides().get(0).getShapes()) {
if (shape instanceof ITable) {
table = (ITable) shape;
//Merge the cells from [0,0] to [3,0]
table.mergeCells(table.get(0, 0), table.get(3, 0), false);
//Merge the cells from [0,1] to [0,5]
table.mergeCells(table.get(0, 1), table.get(0, 5), false);
}
}
//Save the result file
presentation.saveToFile("MergeCells.pptx", FileFormat.PPTX_2010);
presentation.dispose();
}
}

Split Table Cells in PowerPoint
Spire.Presentation for Java also supports users to get the specific cell and split it into smaller ones by calling ITable.get(int columnIndex, int rowIndex) and Cell.split(int RowCount, int ColunmCount) methods. The detailed steps are as follows.
- Create an object of Presentation class.
- Load a sample file using Presentation.loadFromFile() method.
- Declare ITable variable.
- Get the table from the first slide by looping through all shapes.
- Get the specific cell by using ITable.get(int columnIndex, int rowIndex) method and split it into 2 rows and 2 columns by using Cell.split(int RowCount, int ColumnCount) method.
- Save the result file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ITable;
import com.spire.presentation.Presentation;
public class SplitCells {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a sample PowerPoint file
presentation.loadFromFile("sample.pptx");
//Declare ITable variable
ITable table = null;
//Get the table from the first slide by looping through all shapes
for (Object shape : presentation.getSlides().get(0).getShapes()) {
if (shape instanceof ITable) {
table = (ITable) shape;
//Split the cell[2,2] to 2 rows and 2 columns
table.get(2,2).split(2,2);
}
}
//Save the result file
presentation.saveToFile("SplitCells.pptx", FileFormat.PPTX_2010);
presentation.dispose();
}
}

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.
PDF (Portable Document Format) and XPS (XML Paper Specification) are two commonly used document formats for sharing and printing documents. While PDF is widely known and supported, XPS is a Microsoft-developed format that has gained popularity due to its superior graphics rendering capabilities. In this article, we will demonstrate how to use Spire.PDF for Java to convert PDF to XPS and XPS to PDF in high quality.
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>12.4.4</version>
</dependency>
</dependencies>
Convert PDF to XPS in Java
Spire.PDF for Java has a powerful conversion feature, which can convert PDF to XPS in just three steps. The detailed steps are as follows:
- Create a PdfDocument instance.
- Load a PDF sample document using PdfDocument.loadFromFile() method.
- Save the document as XPS using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class PDFtoXPS {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load the PDF file
pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pdf.pdf");
//Save to XPS
pdf.saveToFile("ToXPS.xps", FileFormat.XPS);
pdf.close();
}
}

Convert XPS to PDF in Java
The PdfDocument.saveToFile() method provided by Spire.PDF for Java enables the conversion of a XPS file into a PDF document. The following are steps to convert XPS to PDF.
- Create a PdfDocument instance.
- Load a XPS file document using PdfDocument.loadFromFile() method.
- Save the document as PDF using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class XPStoPDF {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a XPS file
pdf.loadFromXPS("C:\\Users\\Administrator\\Desktop\\sample.xps");
//Save to PDF
pdf.saveToFile("toPDF.pdf", FileFormat.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.
SVG, short for scalable vector graphics, is a vector image format based on XML for two-dimensional graphics. Vector image files, like SVG and PDF files, are very similar. They can display text, images, and other elements in the same appearance and keep the definition no matter how you zoom them. And because of their similarity, PDF files can be converted to SVG files almost losslessly. This article shows an easy method to convert PDF files to SVG files using Spire.PDF for Java.
- Convert Each Page of a PDF File to an SVG File
- Convert All the Pages of a PDF File to a Single SVG File
Install Spire.PDF for Java
First, 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>12.4.4</version>
</dependency>
</dependencies>
Convert Each Page of a PDF File to an SVG File
The detailed steps are as follows:
- Create an object of PdfDocument class.
- Load a PDF document from disk using PdfDocument.loadFromFile() method.
- Convert the document to SVG file and save it using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class PDFToSVG {
public static void main(String[] args) {
//Create an object of Document class
PdfDocument pdf = new PdfDocument();
//Load a PDF document from disk
pdf.loadFromFile("D:/Samples/Sample.pdf");
//Convert the document to SVG and Save it
pdf.saveToFile("D:/javaOutput/PDFToSVG.svg", FileFormat.SVG);
}
}

Convert All the Pages of a PDF File to a Single SVG File
The detailed steps are as follows:
- Create an object of PdfDocument class.
- Load a PDF document from disk using PdfDocument.loadFromFile() method.
- Change the conversion settings to convert the PDF file to a single SVG file using PdfDocument.getConvertOptions().setOutputToOneSvg() method.
- Convert the document to SVG file and save it using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class PDFToSVG {
public static void main(String[] args) {
//Create an object of Document class
PdfDocument pdf = new PdfDocument();
//Load a PDF document from disk
pdf.loadFromFile("D:/Samples/Sample.pdf");
//Change the conversion settings to convert the PDF file to a single SVG file
pdf.getConvertOptions().setOutputToOneSvg(true);
//Convert the document to SVG and Save it
pdf.saveToFile("D:/javaOutput/PDFToSVG.svg", FileFormat.SVG);
}
}

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.