Skip to main content

XmpMetadata Class

Contains XMP metadata associated with a PDF document.

Declaration

public class XmpMetadata extends JavaObject

Remarks

Use one of the following methods to load XMP metadata:

The following code snippet loads XMP metadata from an XML file and embeds it into a PDF document:

import com.devexpress.docs.pdf.*;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (InputStream inputStream = new FileInputStream("Document.pdf");
             PdfDocument pdfDocument = new PdfDocument(inputStream);
             InputStream metadataStream = new FileInputStream("metadata.xml")) {

            pdfDocument.getMetadata().setXmp(
                    XmpMetadata.fromStream(metadataStream)
            );

            try (FileOutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
                pdfDocument.save(outputStream);
            }
        }
    }
}

The following code snippet creates a tagged PDF document, configures PDF/UA metadata, and specifies marked content information through the MarkInfo class. The code snippet enables marked content, user properties, and disables the suspects flag before saving the document.

package pdf;

import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
import com.devexpress.drawing.printing.*;

import java.io.*;
import java.util.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (PdfDocument document = new PdfDocument()) {
            Locale documentLocale = Locale.forLanguageTag("en-US");
            String title = "Invoice";

            // Specify PDF/UA metadata.
            document.getMetadata().getXmp()
                    .getXmpPdfUASchema()
                    .setPart(new XmpInteger(1));

            document.getMetadata().getXmp()
                    .getXmpDublinCoreSchema()
                    .getTitle()
                    .add(documentLocale.toLanguageTag(), title);

            // Specify marked content information.
            MarkInfo markInfo = document.getMarkInfo();
            markInfo.setMarked(true);
            markInfo.setUserProperties(true);
            markInfo.setSuspects(false);

            Page page = document.getPages().add(DXPaperKind.A4);

            // Create the root Document structure element.
            StructureElement root = document.getStructureTree()
                    .addChildElement(Pdf17StructureType.DOCUMENT);

            // Add a section to the document structure.
            StructureElement section = root.addChildElement(Pdf17StructureType.SECT);

            // Add a heading element.
            StructureElement heading = section.addChildElement(Pdf17StructureType.H1);
            heading.addFragment(page, new TextFragment() {{
                setText(title);
                setLocation(new PointF(50, 800));
                setFont(new TextFont("Arial", TextFontStyle.BOLD));
                setFontSize(24);
            }});

            // Add a paragraph element.
            StructureElement paragraph = section.addChildElement(Pdf17StructureType.P);
            paragraph.addFragment(page, new TextFragment() {{
                setText("Invoice details");
                setLocation(new PointF(50, 760));
            }});

            // Save the tagged PDF document.
            try (OutputStream stream =
                         Files.newOutputStream(
                                 Path.of("TaggedDocument.pdf"))) {
                document.save(stream);
            }
        }
    }
}

Refer to the following help topics for additional information:

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
XmpMetadata

Constructors

XmpMetadata() Constructor

Initializes a new instance of the XmpMetadata class.

Declaration

public XmpMetadata()

XmpMetadata(byte[] xmpByteArray) Constructor

Initializes a new instance of the XmpMetadata class from the specified byte array.

Declaration

public XmpMetadata(byte[] xmpByteArray)

Parameters

Name Type Description
xmpByteArray byte[]

The byte array that contains XMP metadata.

XmpMetadata(InputStream stream) Constructor

Initializes a new instance of the XmpMetadata class from the specified input stream.

Declaration

public XmpMetadata(InputStream stream)

Parameters

Name Type Description
stream InputStream

The input stream that contains XMP metadata.

XmpMetadata(ReadableByteChannel channel) Constructor

Initializes a new instance of the XmpMetadata class from the specified byte channel.

Declaration

public XmpMetadata(ReadableByteChannel channel)

Parameters

Name Type Description
channel ReadableByteChannel

The channel that contains XMP metadata.

XmpMetadata(String xmpXml) Constructor

Initializes a new instance of the XmpMetadata class from the specified XML string.

Declaration

public XmpMetadata(String xmpXml)

Parameters

Name Type Description
xmpXml String

The XML string that contains XMP metadata.

Methods

fromByteArray(byte[] xmpByteArray) Method

Creates an XmpMetadata object from a byte array.

Declaration

public static XmpMetadata fromByteArray(byte[] xmpByteArray)

Parameters

Name Type Description
xmpByteArray byte[]

The byte array that contains XMP metadata.

Returns

Type Description
XmpMetadata

An XmpMetadata object created from the specified byte array.

fromStream(InputStream stream) Method

Creates an XmpMetadata object from an input stream.

Declaration

public static XmpMetadata fromStream(InputStream stream)

Parameters

Name Type Description
stream InputStream

The input stream that contains XMP metadata.

Returns

Type Description
XmpMetadata

An XmpMetadata object created from the specified stream.

fromStream(ReadableByteChannel channel) Method

Creates an XmpMetadata object from a byte channel.

Declaration

public static XmpMetadata fromStream(ReadableByteChannel channel)

Parameters

Name Type Description
channel ReadableByteChannel

The channel that contains XMP metadata.

Returns

Type Description
XmpMetadata

An XmpMetadata object created from the specified channel.

fromString(String xmpXml) Method

Creates an XmpMetadata object from an XML string.

Declaration

public static XmpMetadata fromString(String xmpXml)

Parameters

Name Type Description
xmpXml String

The XML string that contains XMP metadata.

Returns

Type Description
XmpMetadata

An XmpMetadata object created from the specified XML string.

getBasicSchema() Method

Returns the basic XMP metadata schema.

Declaration

public XmpBasicSchema getBasicSchema()

Returns

Type Description
XmpBasicSchema

The basic XMP schema.

getCustomSchema() Method

Returns the custom XMP metadata schema.

Declaration

public IXmpCustomSchema getCustomSchema()

Returns

Type Description
IXmpCustomSchema

The custom XMP schema.

getCustomSchema(String namespaceUri) Method

Returns a custom XMP schema with the specified namespace URI.

Declaration

public IXmpCustomSchema getCustomSchema(String namespaceUri)

Parameters

Name Type Description
namespaceUri String

The namespace URI of the schema.

Returns

Type Description
IXmpCustomSchema

The custom XMP schema.

getCustomSchema(XmpPdfAExtensionDescriptor descriptor) Method

Returns a custom XMP schema registered for the specified PDF/A extension.

Declaration

public IXmpCustomSchema getCustomSchema(XmpPdfAExtensionDescriptor descriptor)

Parameters

Name Type Description
descriptor XmpPdfAExtensionDescriptor

The PDF/A extension descriptor.

Returns

Type Description
IXmpCustomSchema

The custom XMP schema.

getNamespaceUriByPrefix(String prefix) Method

Returns the namespace URI associated with the specified prefix.

Declaration

public String getNamespaceUriByPrefix(String prefix)

Parameters

Name Type Description
prefix String

The namespace prefix.

Returns

Type Description
String

The namespace URI.

getPrefixByNamespaceUri(String namespaceUri) Method

Returns the prefix associated with the specified namespace URI.

Declaration

public String getPrefixByNamespaceUri(String namespaceUri)

Parameters

Name Type Description
namespaceUri String

The namespace URI.

Returns

Type Description
String

The namespace prefix.

getRawData() Method

Returns raw XMP metadata access.

Declaration

public XmpRawAccess getRawData()

Returns

Type Description
XmpRawAccess

The object that provides access to raw XMP metadata.

getXmpDublinCoreSchema() Method

Returns the Dublin Core metadata schema.

Declaration

public XmpDublinCoreSchema getXmpDublinCoreSchema()

Returns

Type Description
XmpDublinCoreSchema

The Dublin Core XMP schema.

getXmpPdfAExtensions() Method

PDF/A extension metadata.

Declaration

public XmpPdfAExtensions getXmpPdfAExtensions()

Returns

Type Description
XmpPdfAExtensions

The PDF/A extension metadata.

getXmpPdfASchema() Method

Returns the PDF/A XMP metadata schema.

Declaration

public XmpPdfASchema getXmpPdfASchema()

Returns

Type Description
XmpPdfASchema

The PDF/A XMP schema.

getXmpPdfSchema() Method

Returns the PDF-specific XMP metadata schema.

Declaration

public XmpPdfSchema getXmpPdfSchema()

Returns

Type Description
XmpPdfSchema

The PDF XMP schema.

getXmpPdfUASchema() Method

Returns the PDF/UA XMP metadata schema.

Declaration

public XmpPdfUASchema getXmpPdfUASchema()

Returns

Type Description
XmpPdfUASchema

The PDF/UA XMP schema.

getXmpRightsManagementSchema() Method

Returns the rights management XMP metadata schema.

Declaration

public XmpRightsManagementSchema getXmpRightsManagementSchema()

Returns

Type Description
XmpRightsManagementSchema

The rights management XMP schema.

registerNamespace(String namespaceUri, String preferredPrefix) Method

Registers an XMP namespace with the specified prefix.

Declaration

public boolean registerNamespace(String namespaceUri, String preferredPrefix)

Parameters

Name Type Description
namespaceUri String

The namespace URI.

preferredPrefix String

The preferred namespace prefix.

Returns

Type Description
boolean

true if the namespace is registered successfully; otherwise, false.

serialize(OutputStream stream) Method

Writes XMP metadata to the specified output stream.

Declaration

public void serialize(OutputStream stream)

Parameters

Name Type Description
stream OutputStream

The output stream that receives XMP metadata.

serialize(WritableByteChannel channel) Method

Writes XMP metadata to the specified byte channel.

Declaration

public void serialize(WritableByteChannel channel)

Parameters

Name Type Description
channel WritableByteChannel

The channel that receives XMP metadata.

toByteArray() Method

Converts XMP metadata to a byte array.

Declaration

public byte[] toByteArray()

Returns

Type Description
byte[]

A byte array that contains XMP metadata.

toXmlString() Method

Converts XMP metadata to an XML string.

Declaration

public String toXmlString()

Returns

Type Description
String

The XML string that contains XMP metadata.