Java (486)
In Word documents, the ability to add, modify, and remove table borders flexibly can significantly enhance readability and professionalism. Firstly, customizing border styles highlights important information, helping readers quickly locate key data or paragraphs and enhancing visual impact. Secondly, by adjusting the thickness, color, and style of border lines, finer design control can be achieved, ensuring a uniform and aesthetically pleasing document style. Lastly, removing unnecessary borders helps reduce visual clutter, making page layouts cleaner and more comprehensible, improving the reading experience. This article will introduce how to add, modify, or remove Word table borders in Java projects using Spire.Doc for Java.
Install Spire.Doc for Java
First, you're required to add the Spire.Doc.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.doc</artifactId>
<version>14.10.6</version>
</dependency>
</dependencies>
Java Add Word Table Borders
To uniformly add borders to all cells in a table, you need to visit each cell individually and visually set its border properties. Here are the detailed steps:
- Create a Document object.
- Load a document using the Document.loadFromFile() method.
- Retrieve the first section of the document using Document.getSections().get(0).
- Get the first table within the section using Section.getTables().get(0).
- Use a for loop to iterate through all cells in the table.
- Set the cell border to a single line style by using TableCell.getCellFormat().getBorders().setBorderType(BorderStyle.Single).
- Define the border width to 1 point by using TableCell.getCellFormat().getBorders().setLineWidth(1f).
- Set the border color to black by using TableCell.getCellFormat().getBorders().setColor(Color.black).
- Save the changes to the document using the Document.saveToFile() method.
- Java
import com.spire.doc.*;
import com.spire.doc.documents.*;
import java.awt.*;
public class AddBorder {
public static void main(String[] args) throws Exception{
// Create a new Document object
Document doc = new Document();
// Load the document from file
doc.loadFromFile("TableExample1.docx");
// Get the first section of the document
Section section = doc.getSections().get(0);
// Get the first table in the section
Table table = section.getTables().get(0);
// Declare TableRow and TableCell variables for use in the loop
TableRow tableRow;
TableCell tableCell;
// Iterate through all rows of the table
for (int i = 0; i < table.getRows().getCount(); i++) {
// Get the current row
tableRow = table.getRows().get(i);
// Iterate through all cells in the current row
for (int j = 0; j < tableRow.getCells().getCount(); j++) {
// Get the current cell
tableCell = tableRow.getCells().get(j);
// Set the border style of the current cell to single line
tableCell.getCellFormat().getBorders().setBorderType(BorderStyle.Single);
// Set the width of the border
tableCell.getCellFormat().getBorders().setLineWidth(1f);
// Set the color of the border
tableCell.getCellFormat().getBorders().setColor(Color.black);
}
}
// Save the modified document as a new file
doc.saveToFile("AddBorders.docx", FileFormat.Docx);
// Close the document to release resources
doc.close();
}
}

Java Modify Word Table Borders
Spire.Doc empowers users with extensive customization options for borders, allowing adjustments such as selecting border styles through TableCell.getCellFormat().getBorders().getBottom().setBorderType(), setting border thickness via TableCell.getCellFormat().getBorders().getBottom().setLineWidth(), and specifying border colors with TableCell.getCellFormat().getBorders().getBottom().setColor(). This enables fine-tuned design of table borders within documents according to personal or project needs. Below are the detailed steps:
- Instantiate a Document object.
- Load a document using the Document.loadFromFile() method.
- Retrieve the first section of the document by calling Document.getSections().get(0).
- Get the first table within the section using Section.getTables().get(0).
- Iterate over the cells in the table that require border style changes using a for loop.
- Change the color of the bottom border to orange by invoking TableCell.getCellFormat().getBorders().getBottom ().setColor(Color.ORANGE).
- Alter the style of the bottom border to a dashed line by calling TableCell.getCellFormat().getBorders().getBottom ().setBorderType(BorderStyle.Dot_Dash).
- Modify the width of the bottom border to 2 points by executing TableCell.getCellFormat().getBorders().getBottom ().setLineWidth(2).
- Save the document using the Document.saveToFile() method.
- Java
import com.spire.doc.*;
import com.spire.doc.documents.*;
import java.awt.*;
public class ModifyBorder {
public static void main(String[] args) {
// Create a new Document object
Document doc = new Document();
// Load the document from a file
doc.loadFromFile("TableExample2.docx");
// Get the first section of the document
Section section = doc.getSections().get(0);
// Get the first table in that section
Table table = section.getTables().get(0);
// Declare a TableRow to use within the loop
TableRow tableRow;
// Iterate through all rows of the table
for (int i = 1; i < table.getRows().getCount() - 1; i++) {
tableRow = table.getRows().get(i);
// Set the border color of the current cell tableRow.getCells().get(1).getCellFormat().getBorders().getBottom().setColor(Color.ORANGE);
// Set the border style of the current cell to dotted line
tableRow.getCells().get(1).getCellFormat().getBorders().getBottom().setBorderType(BorderStyle.Dot_Dash);
// Set the width of the border
tableRow.getCells().get(1).getCellFormat().getBorders().getBottom().setLineWidth(2);
}
// Save the modified document as a new file
doc.saveToFile("ModifyBorder.docx", FileFormat.Docx);
// Close the document to release resources
doc.close();
}
}

Java Remove Word Table Borders
When editing Word documents, the flexibility of border design extends beyond the entire table level, allowing for meticulous personalized adjustments at the individual cell level. To comprehensively remove all traces of borders both inside and outside of tables, a phased approach is recommended: Firstly, address the macro-level by clearing the overall border style of the table; subsequently, enter the micro-adjustment phase where each cell within the table is iterated over to revoke its unique border settings. Below are the detailed steps:
- Instantiate a Document object.
- Load a document using the Document.loadFromFile() method.
- Retrieve the first section of the document by calling Document.getSections().get(0).
- Access the first table within the section using Section.getTables().get(0).
- Iterate over all cells in the table using a for loop.
- Remove the border of the table by invoking Table.getTableFormat().getBorders().setBorderType(BorderStyle.None).
- Eliminate the borders of each cell individually by applying TableCell.getCellFormat().getBorders().setBorderType(BorderStyle.None).
- Save the modified document using the Document.saveToFile() method.
- Java
import com.spire.doc.*;
import com.spire.doc.documents.BorderStyle;
public class RemoveBorder {
public static void main(String[] args) {
// Create a new Document object
Document doc = new Document();
// Load the document from a file
doc.loadFromFile("TableExample2.docx");
// Get the first section of the document
Section section = doc.getSections().get(0);
// Get the first table in the section
Table table = section.getTables().get(0);
// Remove the borders set on the table
table.getTableFormat().getBorders().setBorderType(BorderStyle.None);
// Declare a TableRow to use in the loop
TableRow tableRow;
// Iterate through all rows of the table
for (int i = 0; i < table.getRows().getCount(); i++) {
tableRow = table.getRows().get(i);
for (int j = 0; j < tableRow.getCells().getCount(); j++) {
// Remove all borders set on the cell tableRow.getCells().get(j).getCellFormat().getBorders().setBorderType(BorderStyle.None);
}
}
// Save the modified document as a new file
doc.saveToFile("RemoveBorder.docx", FileFormat.Docx);
// Close the document and release resources
doc.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.
Presenting information in a logical sequence is vital for an effective PowerPoint presentation. Reordering slides in a PowerPoint document gives you the flexibility to fine-tune your presentation and ensure that it delivers your message with maximum impact. By organizing your slides strategically, you can create a dynamic and engaging presentation experience.
In this article, you will learn how to reorder slides in a PowerPoint document in Java using the Spire.Presentation for Java library.
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.10.4</version>
</dependency>
</dependencies>
Reorder Slides in a PowerPoint Document in Java
To rearrange the slides in a PowerPoint presentation, you need to create two presentation objects. One object will be used to load the original document while the other will be used to create a new document. By copying the slides from the original document to the new document in the desired order, you can effectively rearrange the slides.
The following are the steps to rearrange slides in a PowerPoint document using Java.
- Create a Presentationobject.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Specify the slide order within an array.
- Create another Presentation object for creating a new presentation.
- Add the slides from the original document to the new presentation in the specified order using Presentation.getSlides().append() method.
- Save the new presentation to a PPTX file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class ReorderSlides {
public static void main(String[] args) throws Exception {
// Create a Presentation object
Presentation presentation = new Presentation();
// Load a PowerPoint file
presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\input.pptx");
// Specify the new slide order within an array
int[] newSlideOrder = new int[] { 3, 4, 1, 2 };
// Create another Presentation object
Presentation new_presentation = new Presentation();
// Remove the default slide
new_presentation.getSlides().removeAt(0);
// Iterate through the array
for (int i = 0; i < newSlideOrder.length; i++)
{
// Add the slides from the original PowerPoint file to the new PowerPoint document in the new order
new_presentation.getSlides().append(presentation.getSlides().get(newSlideOrder[i] - 1));
}
// Save the new presentation to file
new_presentation.saveToFile("output/NewOrder.pptx", FileFormat.PPTX_2019);
// Dispose resources
presentation.dispose();
new_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.
Bookmarks in PDF function as interactive table of contents, allowing users to quickly jump to specific sections within the document. Extracting these bookmarks not only provides a comprehensive overview of the document's structure, but also reveals its core parts or key information, providing users with a streamlined and intuitive method of accessing content. In this article, you will learn how to extract PDF bookmarks in Java 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>12.10.3</version>
</dependency>
</dependencies>
Extract Bookmarks from PDF in Java
With Spire.PDF for Java, you can create custom methods GetBookmarks() and GetChildBookmark() to get the title and text styles of both parent and child bookmarks in a PDF file, then export them to a TXT file. The following are the detailed steps.
- Create a PdfDocument instance.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Get bookmarks collection in the PDF file using PdfDocument.getBookmarks() method.
- Call custom methods GetBookmarks() and GetChildBookmark() to get the text content and text style of parent and child bookmarks.
- Export the extracted PDF bookmarks to a TXT file.
- Java
import com.spire.pdf.*;
import com.spire.pdf.bookmarks.*;
import java.io.*;
public class getAllPdfBookmarks {
public static void main(String[] args) throws IOException{
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a PDF file
pdf.loadFromFile("AnnualReport.pdf");
//Get bookmarks collections of the PDF file
PdfBookmarkCollection bookmarks = pdf.getBookmarks();
//Get the contents of bookmarks and save them to a TXT file
GetBookmarks(bookmarks, "GetPdfBookmarks.txt");
}
private static void GetBookmarks(PdfBookmarkCollection bookmarks, String result) throws IOException {
//create a StringBuilder instance
StringBuilder content = new StringBuilder();
//Get parent bookmarks information
if (bookmarks.getCount() > 0) {
content.append("Pdf bookmarks:");
for (int i = 0; i < bookmarks.getCount(); i++) {
PdfBookmark parentBookmark = bookmarks.get(i);
content.append(parentBookmark.getTitle() + "\r\n");
//Get the text style
String textStyle = parentBookmark.getDisplayStyle().toString();
content.append(textStyle + "\r\n");
GetChildBookmark(parentBookmark, content);
}
}
writeStringToTxt(content.toString(),result);
}
private static void GetChildBookmark(PdfBookmark parentBookmark, StringBuilder content)
{
//Get child bookmarks information
if (parentBookmark.getCount() > 0)
{
content.append("Pdf bookmarks:" + "\r\n");
for (int i = 0; i < parentBookmark.getCount(); i++)
{
PdfBookmark childBookmark = parentBookmark.get(i);
content.append(childBookmark.getTitle() +"\r\n");
//Get the text style
String textStyle = childBookmark.getDisplayStyle().toString();
content.append(textStyle +"\r\n");
GetChildBookmark(childBookmark, content);
}
}
}
public static void writeStringToTxt(String content, String txtFileName) throws IOException {
FileWriter fWriter = new FileWriter(txtFileName, true);
try {
fWriter.write(content);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
fWriter.flush();
fWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}

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.