Webservice Example: Editing XMP Metadata
Minimum technical requirements
- Java version: 7
- webPDF version: 7
- wsclient version: 1
How can XMP metadata be edited using the webPDF wsclient library?
Important note:
The following coding example uses the webPDF wsclient library. To understand and apply it, we recommend reviewing the related wsclient basics first.
To call the webservice, create a REST or SOAP session first and then create either a ToolboxWebService object (SOAP session):
ToolboxWebService toolboxWebService = WebServiceFactory.createInstance(
session,
WebServiceType.TOOLBOX
);
or a ToolboxRestWebService object (REST session):
ToolboxRestWebService toolboxWebService = WebServiceFactory.createInstance(
session,
WebServiceType.TOOLBOX
);
Then pass either a RestDocument or a SoapDocument to this webservice object via setDocument().
Webservice password parameter
To modify a protected document, provide the current open and/or permission password directly on the ToolboxWebService object. If the document has no password protection, this can be skipped.
toolboxWebService.getPassword().setOpen("password");
toolboxWebService.getPassword().setPermission("password");
XMP operation in ToolboxWebService
The ToolboxWebService endpoint includes multiple operations for direct PDF manipulation. One of them is the Xmp operation, which allows adding XMP metadata to a document.
Add an Xmp operation to your webservice object:
XmpType xmp = new XmpType();
toolboxWebService.getOperation().add(xmp);
The following parameters are available for the xmp object.
dataFormat (default: json)
Format of XMP metadata to be imported.
xmp.setDataFormat(XmpDataFormatType.JSON);
Object data
To import XMP data and configure import settings, add an XmpFileDataType object:
XmpFileDataType data = new XmpFileDataType();
xmp.setData(data);
For the expected structure of XMP metadata, see: https://docs.webpdf.de/docs/server/toolbox/xmp-metadata/
source
Defines where XMP data is loaded from:
value= data is passed directly as byte arrayuri= data is referenced via URI
data.setSource(FileDataSourceType.VALUE);
value
Passes XMP data as byte array (source should be value).
data.setValue(FileUtils.readFileToByteArray(new File("...")));
uri
Passes URI reference to XMP data (source should be uri).
data.setUri(new File("...").toURI().toString());
Object namespace
To restrict XMP metadata namespaces, add an XmpNamespaceType object:
XmpNamespaceType namespace = new XmpNamespaceType();
xmp.setNamespace(namespace);
namespaceName (default: "")
Sets a namespace name for XMP metadata.
namespace.setNamespaceName("webPDF XMP Properties");
namespacePrefix (default: "")
Sets a namespace prefix.
namespace.setNamespacePrefix("webPDF");
namespaceURI (default: "")
Sets the namespace URI.
namespace.setNamespaceURI("http://ns.webpdf.de/webpdf/7.0/");
Detailed SOAP example
try (
// Create webPDF session (SOAP)
SoapSession session = SessionFactory.createInstance(
WebServiceProtocol.SOAP,
new URL("https://localhost:8080/webPDF/")
);
// Provide source and target files
SoapDocument soapDocument = new SoapDocument(
new File("Path to source document").toURI(),
new File("Path to target document")
)
) {
// Webservice call
} catch (IOException ex) {
// Error handling
}