You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Peter Pinnau <pe...@unterbrecher.de> on 2017/05/17 09:27:12 UTC

Custom XMP schemas with xmpbox

I would like to implement a custom XMP schema and add/read that metadata 
using xmpbox.

According to the sources of the schema implementations shipped with 
xmpbox I created a simple test schema:

@StructuredType(preferedPrefix = "feed", namespace = 
"http://pinnau.biz/dms/feed/elements/1.1/")
public class FeedXMPSchema extends XMPSchema {

     @PropertyType(type = Types.Text, card = Cardinality.Simple)
     public static final String IDENTIFIER = "test";

     public FeedXMPSchema(XMPMetadata metadata) {
         super(metadata);
     }

     public FeedXMPSchema(XMPMetadata metadata, String prefix) {
         super(metadata, prefix);
     }

     public void setTest(String test) {
         addProperty(createTextType(IDENTIFIER, test));
     }

     public String getTest() {
         TextType tt = (TextType) getProperty(IDENTIFIER);
         return tt == null ? null : tt.getStringValue();
     }
}


It seems that I am able to write metadata to a PDDocument via:

XMPMetadata xmp = XMPMetadata.createXMPMetadata();

PDMetadata metadata = new PDMetadata(doc);

FeedXMPSchema feedSchema = new FeedXMPSchema(xmp);
feedSchema.setTest("This is a test.");
xmp.addSchema(feedSchema);

XmpSerializer serializer = new XmpSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(xmp, baos, true);
metadata.importXMPMetadata( baos.toByteArray() );

doc.getDocumentCatalog().setMetadata(metadata);


Unfortunately an exception is thrown when I try to parse the XMP from 
the document:

org.apache.xmpbox.xml.XmpParsingException: Cannot find a definition for 
the namespace http://pinnau.biz/dms/feed/elements/1.1/


I believe that the parser does not know of my schema implementation. I 
searched for a possibility to register my class somewhere but did not 
find a solution.

Is there a way to get this working?

Thanks


-- 
Viele Grüße
Peter Pinnau


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org