Creating and Updating PDF Xpath metadata
Posted: Fri Aug 03, 2018 9:35 am
Hi!
We´re testing using pdf metadata in our workflows and we have a problem updating Xpath data (Title, Author, Subject etc) via scripting. We´ve managed to update this data, if the pdf already has something in those fields. If the fields are empty, the xmp (xml) data structure doesn´t have the tags in the data tree and we can´t figure out how to create the tags needed via scripting. Here´s the Switch script we´re trying, but it doesn´t create anything to the xmp tree...
function jobArrived( s : Switch, job : Job )
{
//get a writable XMP Dataset
var ds = job.getEmbeddedDataset(true);
var pdfTitle = s.getPropertyValue("pdfTitle");
var pdfAuthor = s.getPropertyValue("pdfAuthor");
var pdfSubject = s.getPropertyValue("pdfSubject");
var keyword1 = s.getPropertyValue("keyword1");
var keyword2 = s.getPropertyValue("keyword2");
var keyword3 = s.getPropertyValue("keyword3");
//get the default prefixmap
var map = ds.createDefaultMap();
ds.setString('dc:title/*[1]', map, pdfTitle);
//ds.setString('dc:title/*[x-default]', map, 'John Doe');
ds.setString('mns:general/mns:author', map, 'John Doe');
ds.setString('xmp:general/mns:author', map, 'John Doe');
ds.setString('dc:creator/*[1]', map, pdfAuthor);
ds.setString('dc:description/*[1]', map, pdfSubject);
ds.setString('dc:subject/*[1]', map, keyword1);
ds.setString('dc:subject/*[2]', map, keyword2);
ds.setString('dc:subject/*[3]', map, keyword3);
//finished with writing
ds.finishWriting();
//save file
job.sendToSingle(job.getPath());
}
We´re testing using pdf metadata in our workflows and we have a problem updating Xpath data (Title, Author, Subject etc) via scripting. We´ve managed to update this data, if the pdf already has something in those fields. If the fields are empty, the xmp (xml) data structure doesn´t have the tags in the data tree and we can´t figure out how to create the tags needed via scripting. Here´s the Switch script we´re trying, but it doesn´t create anything to the xmp tree...
function jobArrived( s : Switch, job : Job )
{
//get a writable XMP Dataset
var ds = job.getEmbeddedDataset(true);
var pdfTitle = s.getPropertyValue("pdfTitle");
var pdfAuthor = s.getPropertyValue("pdfAuthor");
var pdfSubject = s.getPropertyValue("pdfSubject");
var keyword1 = s.getPropertyValue("keyword1");
var keyword2 = s.getPropertyValue("keyword2");
var keyword3 = s.getPropertyValue("keyword3");
//get the default prefixmap
var map = ds.createDefaultMap();
ds.setString('dc:title/*[1]', map, pdfTitle);
//ds.setString('dc:title/*[x-default]', map, 'John Doe');
ds.setString('mns:general/mns:author', map, 'John Doe');
ds.setString('xmp:general/mns:author', map, 'John Doe');
ds.setString('dc:creator/*[1]', map, pdfAuthor);
ds.setString('dc:description/*[1]', map, pdfSubject);
ds.setString('dc:subject/*[1]', map, keyword1);
ds.setString('dc:subject/*[2]', map, keyword2);
ds.setString('dc:subject/*[3]', map, keyword3);
//finished with writing
ds.finishWriting();
//save file
job.sendToSingle(job.getPath());
}