Skip to main content

XmpRawAccess Class

Accesses raw XMP metadata properties (XML nodes).

Declaration

public class XmpRawAccess extends JavaObject

Remarks

Use the XmpMetadata.getRawData() method to obtain an XmpRawAccess object and access XMP metadata properties as raw XML nodes. You can use XmpRawAccess methods to get, set, and remove property values.

Use qualified names in the URI:name or prefix:name format to identify properties.

Set Property Values

Use the XmpRawAccess.setString() method to set a property value.

The specified property must exist in the XMP namespace and support string values. Use the XmpMetadata.registerNamespace() method to register a custom namespace before you set properties that are not included in predefined XMP namespaces.

The following code snippet sets Label and CreatorTool property values in the Basic XMP namespace:

package pdf;

import com.devexpress.docs.pdf.*;

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

public class Main {
    public static void main(String[] args) throws Exception {
        try (FileChannel channel = FileChannel.open(Path.of("document.pdf"));
             PdfDocument pdfDocument = new PdfDocument(channel);
             FileInputStream xmlStream = new FileInputStream("metadata.xml")) {

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

            XmpRawAccess xmpRawAccess = pdfDocument.getMetadata()
                    .getXmp()
                    .getRawData();

            xmpRawAccess.setString("xmp:Label", "Updated Label");
            xmpRawAccess.setString("xmp:CreatorTool", "Updated Creator Tool");

            try (WritableByteChannel writableByteChannel =
                         FileChannel.open(Path.of("Result.pdf"),
                                 StandardOpenOption.CREATE,
                                 StandardOpenOption.WRITE,
                                 StandardOpenOption.TRUNCATE_EXISTING)) {

                pdfDocument.save(writableByteChannel);
            }
        }
    }
}

Obtain Property Values

Call the XmpRawAccess.getString() method to obtain a property value.

The following code snippet obtains Label and CreatorTool property values from the Basic XMP namespace:

package pdf;

import com.devexpress.docs.pdf.*;

import java.nio.channels.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (FileChannel channel = FileChannel.open(Path.of("Result.pdf"));
             PdfDocument pdfDocument = new PdfDocument(channel)) {

            XmpRawAccess xmpRawAccess = pdfDocument.getMetadata()
                    .getXmp()
                    .getRawData();

            String label = xmpRawAccess.getString("xmp:Label");
            String creatorTool = xmpRawAccess.getString("xmp:CreatorTool");
        }
    }
}

Refer to the following help topic for additional information: Manage PDF Document Properties and XMP Metadata.

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
XmpRawAccess

Methods

contains(String qualifiedName) Method

Checks whether the specified XMP metadata property exists.

Declaration

public boolean contains(String qualifiedName)

Parameters

Name Type Description
qualifiedName String

The qualified property name.

Returns

Type Description
boolean

true if the property exists; otherwise, false.

getCount() Method

Returns the number of XMP metadata properties.

Declaration

public int getCount()

Returns

Type Description
int

The number of XMP metadata properties.

getString(String qualifiedName) Method

Returns the string value of the specified XMP metadata property.

Declaration

public String getString(String qualifiedName)

Parameters

Name Type Description
qualifiedName String

The qualified property name in the prefix:name or URI:name format.

Returns

Type Description
String

The property value.

remove(String qualifiedName) Method

Removes the specified XMP metadata property.

Declaration

public boolean remove(String qualifiedName)

Parameters

Name Type Description
qualifiedName String

The qualified property name in the prefix:name or URI:name format.

Returns

Type Description
boolean

true if the property was removed; otherwise, false.

setString(String qualifiedName, String value) Method

Sets the string value of the specified XMP metadata property.

Declaration

public void setString(String qualifiedName, String value)

Parameters

Name Type Description
qualifiedName String

The qualified property name in the prefix:name or URI:name format.

value String

The property value.

Remarks

The specified prefix must refer to a registered XMP namespace. Use XmpMetadata.setRegisterNamespace to register a custom namespace before setting properties from that namespace.