Microsoft Publisher (PUB) files store metadata along with their pages. This includes the title, author, keywords, company, and other document properties. You can use these properties to catalog flyers, brochures, and newsletters, search large archives, or check who last worked on a publication.

In this tutorial, you’ll learn how to read and edit PUB metadata in Java using Aspose.PUB for Java. You’ll also learn how to keep the updated metadata by applying it to a PDF version of the publication. The code runs on any platform that supports Java and doesn’t need Microsoft Publisher.

Java Library to Read and Edit PUB Metadata

Aspose.PUB for Java is a library for reading Microsoft Publisher PUB files and converting them to PDF in Java applications. It exposes the document properties of a PUB file through two classes:

  • SummaryInfo contains the title, subject, author, last author, keywords, and comments.
  • DocSummaryInfo contains the category, company, and language.

Both classes provide getter and setter methods, so you can read and update each property:

PropertyClassReadEdit
Title, Subject, AuthorSummaryInfogetTitle(), getSubject(), getAuthor()setTitle(), setSubject(), setAuthor()
Last Author, Keywords, CommentsSummaryInfogetLastAuthor(), getKeywords(), getComments()setLastAuthor(), setKeywords(), setComments()
Category, Company, LanguageDocSummaryInfogetCategory(), getCompany(), getLanguage()setCategory(), setCompany(), setLanguage()

Add the following repository and dependency to your project’s pom.xml file:

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://releases.aspose.com/java/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pub</artifactId>
        <version>22.8</version>
    </dependency>
</dependencies>

You can also download the JAR from the releases section.

Read PUB Metadata in Java

Follow these steps to read the metadata of a PUB file:

  1. Load the PUB file using the PubFactory.createParser() method.
  2. Parse the file into a Document object using the parse() method.
  3. Get the summary information using the getSummaryInfo() method and read the title, subject, author, and other values.
  4. Get the document summary information using the getDocumentSummaryInfo() method and read the category, company, and language.

The following Java code shows how to read the metadata of a PUB file:

import com.aspose.pub.DocSummaryInfo;
import com.aspose.pub.Document;
import com.aspose.pub.IPubParser;
import com.aspose.pub.PubFactory;
import com.aspose.pub.SummaryInfo;

public class ReadPubMetadata {
    public static void main(String[] args) {
        // Path to the documents directory
        String dataDir = "C:\\Files\\";

        // Load the PUB file
        IPubParser parser = PubFactory.createParser(dataDir + "halloween-flyer.pub");

        // Parse the file into a Document object
        Document document = parser.parse();

        // Read the summary information
        SummaryInfo summary = document.getSummaryInfo();
        System.out.println("Title: " + summary.getTitle());
        System.out.println("Subject: " + summary.getSubject());
        System.out.println("Author: " + summary.getAuthor());
        System.out.println("Last Author: " + summary.getLastAuthor());
        System.out.println("Keywords: " + summary.getKeywords());
        System.out.println("Comments: " + summary.getComments());

        // Read the document summary information
        DocSummaryInfo docSummary = document.getDocumentSummaryInfo();
        System.out.println("Category: " + docSummary.getCategory());
        System.out.println("Company: " + docSummary.getCompany());
        System.out.println("Language: " + docSummary.getLanguage());
    }
}

The sample flyer only stores the author name, so the other properties are empty:

Title:
Subject:
Author: Authorized User
Last Author:
Keywords:
Comments:
Category:
Company:
Language:

A property is empty when it was never set in the original publication. Check for empty values before you use the metadata in your application. To also read the page size, fonts, and colors of a publication, see Read PUB File using Java.

Edit PUB Metadata in Java

You can update the metadata of a parsed PUB document using the setter methods of SummaryInfo and DocSummaryInfo. Follow these steps:

  1. Load and parse the PUB file.
  2. Update the summary information using setTitle(), setSubject(), setAuthor(), setLastAuthor(), setKeywords(), and setComments().
  3. Update the document summary information using setCategory(), setCompany(), and setLanguage().

The following Java code shows how to edit the metadata of a PUB file:

import com.aspose.pub.DocSummaryInfo;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import com.aspose.pub.SummaryInfo;

public class EditPubMetadata {
    public static void main(String[] args) {
        // Path to the documents directory
        String dataDir = "C:\\Files\\";

        // Load and parse the PUB file
        Document document = PubFactory.createParser(dataDir + "halloween-flyer.pub").parse();

        // Update the summary information
        SummaryInfo summary = document.getSummaryInfo();
        summary.setTitle("Halloween Party 2026");
        summary.setSubject("Community event flyer");
        summary.setAuthor("Events Team");
        summary.setLastAuthor("Marketing Team");
        summary.setKeywords("halloween, party, flyer");
        summary.setComments("Metadata updated with Aspose.PUB for Java");

        // Update the document summary information
        DocSummaryInfo docSummary = document.getDocumentSummaryInfo();
        docSummary.setCategory("Flyers");
        docSummary.setCompany("Contoso Events");
        docSummary.setLanguage("English");

        // Print the updated values
        System.out.println("Title: " + summary.getTitle());
        System.out.println("Subject: " + summary.getSubject());
        System.out.println("Author: " + summary.getAuthor());
        System.out.println("Last Author: " + summary.getLastAuthor());
        System.out.println("Keywords: " + summary.getKeywords());
        System.out.println("Comments: " + summary.getComments());
        System.out.println("Category: " + docSummary.getCategory());
        System.out.println("Company: " + docSummary.getCompany());
        System.out.println("Language: " + docSummary.getLanguage());
    }
}
Title: Halloween Party 2026
Subject: Community event flyer
Author: Events Team
Last Author: Marketing Team
Keywords: halloween, party, flyer
Comments: Metadata updated with Aspose.PUB for Java
Category: Flyers
Company: Contoso Events
Language: English

Note: These changes apply to the Document object in memory. Aspose.PUB for Java doesn’t write PUB files, so you can’t save the updated metadata back to the original publication. The PDF converter also doesn’t copy these values into the output file. The next section shows how to keep the metadata in a PDF file.

Save PUB Metadata to PDF in Java

PDF is the most common format for sharing Publisher files. To keep the updated metadata, convert the PUB document to PDF and apply the values to the PDF document properties using Aspose.PDF for Java.

Add the following dependency to your pom.xml file. It uses the same Aspose repository as Aspose.PUB:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>26.10</version>
</dependency>

Then follow these steps:

  1. Load and parse the PUB file, then update its metadata.
  2. Convert the document to PDF in a ByteArrayOutputStream using the convertToPdf() method.
  3. Open the PDF data with the com.aspose.pdf.Document class.
  4. Copy the metadata to the PDF document using the setter methods of getInfo().
  5. Save the PDF file using the save() method.

The following Java code shows how to save PUB metadata to a PDF file:

import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import com.aspose.pub.SummaryInfo;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

public class SavePubMetadataToPdf {
    public static void main(String[] args) {
        // Path to the documents directory
        String dataDir = "C:\\Files\\";

        // Load and parse the PUB file
        Document document = PubFactory.createParser(dataDir + "halloween-flyer.pub").parse();

        // Update the metadata
        SummaryInfo summary = document.getSummaryInfo();
        summary.setTitle("Halloween Party 2026");
        summary.setSubject("Community event flyer");
        summary.setAuthor("Events Team");
        summary.setKeywords("halloween, party, flyer");

        // Convert the PUB document to PDF in memory
        ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
        PubFactory.createPdfConverter().convertToPdf(document, pdfStream);

        // Open the PDF and apply the updated metadata
        com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(new ByteArrayInputStream(pdfStream.toByteArray()));
        pdf.getInfo().setTitle(summary.getTitle());
        pdf.getInfo().setSubject(summary.getSubject());
        pdf.getInfo().setAuthor(summary.getAuthor());
        pdf.getInfo().setKeywords(summary.getKeywords());

        // Save the PDF file
        pdf.save(dataDir + "halloween-flyer_out.pdf");
        pdf.close();
    }
}

Open the PDF in any viewer and check its document properties. The title, subject, author, and keywords match the values you set on the PUB document.

The Document class name exists in both libraries, so the code uses the full name com.aspose.pdf.Document for the PDF document. Learn more about PDF conversion in Convert PUB to PDF in Java.

Get a Free License

You can request a free temporary license to evaluate Aspose.PUB for Java without limitations. Apply the license in your application before running the examples.

Read and Edit PUB Metadata: Free Resources

Learn more about working with Publisher files using these resources:

Conclusion

You can now read and edit PUB metadata in Java using Aspose.PUB for Java. Use the getSummaryInfo() and getDocumentSummaryInfo() methods to inspect Publisher files, and copy the updated values to a PDF file when you need to keep them. If you have any questions, post them on our free support forum.

Frequently Asked Questions

How do I read the metadata of a PUB file in Java?

Load the PUB file using PubFactory.createParser(), call parse() to get a Document, and then read the values returned by getSummaryInfo() and getDocumentSummaryInfo().

Which PUB metadata properties can I edit in Java?

You can set the title, subject, author, last author, keywords, and comments through SummaryInfo, and the category, company, and language through DocSummaryInfo.

Can I save the edited metadata back to the PUB file?

No. Aspose.PUB for Java reads PUB files and converts them to PDF. It doesn’t write PUB files, so the edited metadata exists in memory only.

How can I keep the updated metadata?

Convert the PUB document to PDF and apply the updated values to the PDF document properties using Aspose.PDF for Java.

Why are some metadata properties empty?

A property is empty when it was never set in the original PUB file. Many publications only store the author name.

Do I need Microsoft Publisher installed to read PUB metadata in Java?

No. Aspose.PUB for Java reads PUB files on its own, so you don’t need Microsoft Publisher or any other software.

See Also