Programming with Documents | Java

Contents
[ Hide Show ]

Aspose.PUB for Java facilitates you to manipulate .pub files in your applications. Its well-defined structure lets you read PUB files and work with the file properties.

Edit MetaData of PUB Files

MetaData of a document describes a file in terms of its properties such as author, title, last author, company, language, and other similar information. This is useful information that is stored along with the document. Aspose.PUB for Java lets you edit metadata of a PUB file using the DocSummaryInfo and SummaryInfo classes as shown in the following code sample.

 1    IPubParser parser = PubFactory.createParser(fileName);
 2    Document document = parser.parse();
 3
 4    document.getDocumentSummaryInfo().setCategory("category");
 5    document.getDocumentSummaryInfo().setCompany("company");
 6    document.getDocumentSummaryInfo().setLanguage("language");
 7
 8    document.getSummaryInfo().setComments("comments");
 9    document.getSummaryInfo().setKeywords("keywords");
10    document.getSummaryInfo().setLastAuthor("last author");
11    document.getSummaryInfo().setTitle("title");
12    document.getSummaryInfo().setSubject("subject");

The given code snippet is written in Java. It demonstrates how to manipulate the metadata of a .pub file using a library or API related to PubFactory using Aspose.PUB API Solution for Java.

Let’s briefly explain the code:

  1. It declares an IPubParser object named parser and initializes it using the createParser method from the PubFactory class, passing the fileName as a parameter.

  2. It declares a Document object named document and assigns it the result of calling the parse method on the parser object.

  3. It uses the getDocumentSummaryInfo method of the document object to access the document’s summary information and sets the values for various properties like category, company, and language. In this code snippet, these properties are being modified with specific values.

  4. It uses the getSummaryInfo method of the document object to access the summary information of the document and sets the values for properties like comments, keywords, last author, title, and subject. These properties are also being modified with specific values.

To learn the complete Java code examples and data files, please go to Aspose.PUB-Documentation for Java Github project.

Try also this and other functionality provided by Aspose.PUB implemented into a set of cross-platform applications to manipulate .pub files.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.