Java (480)
Java: Set, Retrieve, or Delete Document Properties in PowerPoint
2023-08-10 07:54:00 Written by KoohjiDocument properties of PowerPoint presentations hold immense value in managing and organizing presentations. The information in properties, including title, author, keywords, etc., provides a concise summary, aids in categorization and searchability, and contributes to maintaining a comprehensive presentation history. However, some useless document properties need to be deleted to prevent them from affecting document management. This article is going to show how to add, retrieve, or delete document properties in PowerPoint presentations using Spire.Presentation for Java.
- Add Document Properties to a PowerPoint Presentation
- Retrieve Document Properties from a PowerPoint Presentation
- Delete Document Properties of a PowerPoint Presentation
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>
Add Document Properties to a PowerPoint Presentation
Spire.Presentation for Java provides a set of methods under IDocumentProperty class to enable users to set and retrieve document properties of a presentation after getting the properties using the Presentation.getDocumentProperty() method. The detailed steps for adding document properties to a PowerPoint presentation are as follows:
- Create an object of Presentation class.
- Load a presentation file using Presentation.loadFromFile() method.
- Get the document properties of the presentation using Presentation.getDocumentProperty() method.
- Set the document properties using methods under IDocumentProperty class.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;
public class addPresentationProperties {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a PowerPoint presentation
presentation.loadFromFile("Sample.pptx");
//Get the properties of the presentation and add items
IDocumentProperty property = presentation.getDocumentProperty();
property.setTitle("Annual Business Analysis Report");
property.setSubject("Business Analysis");
property.setAuthor("Taylor");
property.setManager("John");
property.setCompany("E-iceblue");
property.setCategory("Report");
property.setKeywords("Operating Analysis; Quarterly Operating Data; Growth");
property.setComments("The report has been revised and finalized and does not require further consultation.");
//Save the presentation file
presentation.saveToFile("AddProperties.pptx", FileFormat.AUTO);
presentation.dispose();
}
}

Retrieve Document Properties from a PowerPoint Presentation
The detailed steps for retrieving document properties from a PowerPoint presentation are as follows:
- Create an object of Presentation class.
- Load a presentation file using Presentation.loadFromFile() method.
- Get the properties of the presentation using Presentation.getDocumentProperty() method.
- Retrieve property information using methods under IDocumentProperty class and write it to a text file.
- Java
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;
import java.io.FileWriter;
public class retrievePresentationProperties {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a presentation file
presentation.loadFromFile("AddProperties.pptx");
//Get the properties of the presentation
IDocumentProperty property = presentation.getDocumentProperty();
//Get the properties and write them to a text file
String properties = "Title: " + property.getTitle() + "\r\n"
+ "Subject: " + property.getSubject() + "\r\n"
+ "Author: " + property.getAuthor() + "\r\n"
+ "Manager: " + property.getManager() + "\r\n"
+ "Company: " + property.getCompany() + "\r\n"
+ "Category: " + property.getCategory() + "\r\n"
+ "Keywords: " + property.getKeywords() + "\r\n"
+ "Comments: " + property.getComments();
FileWriter presentationProperties = new FileWriter("PresentationProperties.txt");
presentationProperties.write(properties);
presentationProperties.close();
}
}

Delete Document Properties of a PowerPoint Presentation
Removing document properties from a presentation is similar to adding properties. Just set the property data to null and the document properties can be removed. The details are as follows:
- Create an object of Presentation class.
- Load a presentation file using Presentation.loadFromFile() method.
- Get the document properties of the presentation using Presentation.getDocumentProperty() method.
- Set the document properties to null using methods under IDocumentProperty class.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;
public class deletePresentationProperties {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation presentation = new Presentation();
//Load a PowerPoint presentation
presentation.loadFromFile("AddProperties.pptx");
//Get the properties of the presentation and set the properties to null
IDocumentProperty property = presentation.getDocumentProperty();
property.setTitle("");
property.setSubject("");
property.setAuthor("");
property.setManager("");
property.setCompany("");
property.setCategory("");
property.setKeywords("");
property.setComments("");
//Save the presentation file
presentation.saveToFile("DeleteProperties.pptx", FileFormat.AUTO);
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.
Java convert PDF to HTML with embedded SVG/Image and save HTML to stream
2020-04-15 08:12:08 Written by KoohjiSpire.PDF supports to convert PDF to HTML and save the resulted HTML file to stream by calling the method PdfDocument.saveToStream(). When converting PDF to HTML, it also supports to set the convert options with embedded SVG/Image on the resulted HTML file. This article will demonstrate how to convert the PDF pages to HTML with embedded SVG and embedded image.
import com.spire.pdf.*;
import java.io.*;
public class PDFtoHTML {
public static void main(String[] args) throws FileNotFoundException {
String inputFile = "Sample.pdf";
String outputFile = "output/toHTML_out.html";
//Load the sample document file
PdfDocument pdf = new PdfDocument();
pdf .loadFromFile(inputFile);
//Set the bool useEmbeddedSvg and useEmbeddedImg as true
pdf .getConvertOptions().setPdfToHtmlOptions(true,true);
//Save to stream
File outFile = new File(outputFile);
OutputStream outputStream = new FileOutputStream(outFile);
pdf.saveToStream(outputStream, FileFormat.HTML);
pdf.close();
}
}
This article demonstrates how to highlight the highest and lowest value in a cell rang through conditional formatting. You can also highlight the top 5 or bottom 5 values by passing 5 to setRank() method in the code snippet below.
import com.spire.xls.*;
import java.awt.*;
public class HighlightTopBottom {
public static void main(String[] args) {
//Create a Workbook object
Workbook workbook = new Workbook();
//Load the sample Excel file
workbook.loadFromFile("G:\\360MoveData\\Users\\Administrator\\Desktop\\sales report.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Apply conditional formatting to range "B2:E5" to highlight the highest value
ConditionalFormatWrapper format1 = sheet.getCellRange("B2:E5").getConditionalFormats().addCondition();
format1.setFormatType(ConditionalFormatType.TopBottom);
format1.getTopBottom().setType(TopBottomType.Top);
format1.getTopBottom().setRank(1);
format1.setBackColor(Color.red);
//Apply conditional formatting to range "B2:E5" to highlight the lowest value
ConditionalFormatWrapper format2 = sheet.getCellRange("B2:E5").getConditionalFormats().addCondition();
format2.setFormatType(ConditionalFormatType.TopBottom);
format2.getTopBottom().setType(TopBottomType.Bottom);
format2.getTopBottom().setRank(1);
format2.setBackColor(Color.yellow);
//Save the document
workbook.saveToFile("output/HighestLowestValue.xlsx", ExcelVersion.Version2016);
}
}
