Use PDF metadata editing to standardize document properties and improve search workflows.

Common use cases include:

  • Updating title and author fields
  • Normalizing metadata across large document sets
  • Exporting metadata for audit or integration workflows

This guide also shows how to export Extensible Metadata Platform (XMP) metadata as XML.

Download sample

How Nutrient helps

Nutrient Java SDK provides metadata APIs for reading, updating, and exporting PDF metadata.

The SDK enables you to:

  • Update standard properties such as title and author
  • Export XMP as XML
  • Integrate metadata updates into existing Java workflows

Preparing the project

Start by specifying a package name and importing the required classes:

package io.nutrient.Sample;
import io.nutrient.sdk.Document;
import io.nutrient.sdk.exceptions.NutrientException;
import io.nutrient.sdk.editors.PdfEditor;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

Create the main method and declare checked exceptions used in this sample:

public class PDFMetadataEditor {
public static void main(String[] args) throws NutrientException, IOException {

Working with PDF metadata

Open the PDF in a try-with-resources statement(opens in a new tab) so Java closes resources after processing.

In this sample, you open from a file path. The SDK also supports streams:

input.pdf must exist in the current working directory. If the file is located elsewhere, use an absolute path (for example, C:\\docs\\input.pdf).

try (Document document = Document.open("input.pdf")) {

Create a PdfEditor instance to update document metadata:

PdfEditor editor = PdfEditor.edit(document);

Modifying metadata properties

Update metadata fields such as author and title:

editor.getMetadata().setAuthor("New author value");
editor.getMetadata().setTitle("New title value");

Exporting XMP metadata

Export XMP metadata as XML for inspection, backup, or integration:

String xmpMetadata = editor.getMetadata().getXMP();
try (FileWriter writer = new FileWriter("output_metadata.xml")) {
writer.write(xmpMetadata);
}

Saving the modified PDF

Save the modified PDF after metadata updates:

editor.saveAs("output.pdf");
editor.close();
}
}
}

Error handling

The sample can throw:

  • NutrientException for SDK and document-processing issues
  • IOException for file I/O operations

In production code:

  • Catch these exceptions.
  • Return clear error messages.
  • Log failure details for debugging.

Conclusion

Use this workflow to edit PDF metadata:

  1. Open the document with try-with-resources.
  2. Create a PdfEditor.
  3. Update metadata fields such as author and title.
  4. Export XMP metadata with getXMP().
  5. Save the modified PDF with saveAs().

For related document workflows, refer to the Java SDK guides.

Download this ready-to-use sample package.