Page 1 of 1
Extract from XMP and insert into XML
Posted: Wed Apr 04, 2012 5:30 pm
by Clive Andrews
I know the probable answer here, but nothing gained by not asking....
Is there an easy/quick way to extract some XMP info from a PDF and write it into an XML file?
I have this "cunning plan"....
:)
Extract from XMP and insert into XML
Posted: Wed Apr 04, 2012 10:42 pm
by dkelly
Apago PDFspy can retrieve XMP for document and/or individual images.
Extract from XMP and insert into XML
Posted: Thu Apr 05, 2012 9:26 am
by Clive Andrews
Yes sir, I can get to the XMP as metadata anyway - what I want to do is take a PDF, inject an XML template - but merge some extra data from the PDF itself into the metadata I have attached. It seems the easy way would be to dynamically modify the content of the Template before I inject it....
I'm trying to avoid having lots of similar flows - I have a good preflight, report and archive flow, but we will potentially get files delivered by FTP direct into Switch (iDropper or Switch clients are not an option) I can get them to embed the relevant info the source PDF - probably just the creator file name, so would like to merge that into our HTML email template....
Extract from XMP and insert into XML
Posted: Thu Apr 05, 2012 4:06 pm
by dkelly
In that case, you can extract the XMP using Switch, modify it using an XSLT transform and write it back using XMP update.
Extract from XMP and insert into XML
Posted: Sat Apr 07, 2012 7:59 pm
by Clive Andrews
dkelly wrote: In that case, you can extract the XMP using Switch, modify it using an XSLT transform and write it back using XMP update.
Gotcha - simples!
I'm still trying to get my head round XSLT transformation (ok, stealing a lot of your work) - but I'll get there...
Thank you sir, happy easter!
Extract from XMP and insert into XML
Posted: Mon Apr 09, 2012 3:26 pm
by dkelly
Give me a simple example of what you are trying to do and I'll see if I have an XSLT that I can easily modify for you.
Extract from XMP and insert into XML
Posted: Tue Apr 10, 2012 10:19 am
by Clive Andrews
No worries Dwight.
The xml template I have is:
Customer upload
FTP
Upload
c.andrews@printing-press-press.co.uk
Joe
Bloggs
01388 212716
customer_name@printing-press.co.uk
FTP Upload
Joe Bloggs Inc
I am trying to change the "Reference" - in BOLD and Red using the variable "dc:title" from XMP in the PDF - (I'm renaming it with [Metadata.Text:Path="dc:title/*[@xml:lang='x-default']"]
So it should be easy (if I knew what I was doing)
Obviously, I could use this as a base for a lot more - once I see how to do it.
My plan is to then squirt this folder back into my normal flows for preflight and reporting - and all I need the customer to do is get the ISBN into the Title field on the PDF document info, and I can then use it to marry up to the ISBN that will be raised by an EDI order (JDF)
Thanks Dwight.
Extract from XMP and insert into XML
Posted: Tue Apr 10, 2012 4:56 pm
by dkelly
Try this:
function jobArrived( s : Switch, job : Job )
{
var theXmp = job.getDataset("Xmp");
var theCreator = "Unknown";
if (theXmp != null)
theCreator = theXmp.getString( "dc:creator/*[1]" , null );
var theXML = new Document();
// create the root node
var rootElem = theXML.createElement( "jobInfo", null );
theXML.appendChild( rootElem );
// create the children nodes
var theChildNode = theXML.createElement( "uuid", null );
rootElem.appendChild( theChildNode );
var theValue = theXML.createText( "Customer upload" );
theChildNode.appendChild( theValue );
theChildNode = theXML.createElement( "First_name", null );
rootElem.appendChild( theChildNode );
theValue = theXML.createText( "FTP" );
theChildNode.appendChild( theValue );
theChildNode = theXML.createElement( "Reference", null );
rootElem.appendChild( theChildNode );
theValue = theXML.createText( theCreator );
theChildNode.appendChild( theValue );
// save the XML document
var theDataset = job.createDataset("XML");
var theXMLFilename = theDataset.getPath();
theXML.save(theXMLFilename);
job.setDataset("jobticket", theDataset);
delete theXML;
job.sendToSingle(job.getPath());
}
You'll have to create the other elements but this will get you started.
Cheers,
Dwight Kelly
Apago, Inc.
dkelly@apago.com
tips accepted

Extract from XMP and insert into XML
Posted: Tue Apr 10, 2012 5:16 pm
by Clive Andrews
Yes - I see, that's easier, just use the script to write the XML, with static values for all bar that 1. That appears to mean I don't need to inject a static file anymore?
Extract from XMP and insert into XML
Posted: Tue Apr 10, 2012 5:29 pm
by dkelly
No reason you couldn't read the injected template XML and modify it instead of creating it from scratch.. Document() creator optional takes a filename of existing XML file to read.
Extract from XMP and insert into XML
Posted: Wed Apr 11, 2012 12:15 pm
by Clive Andrews
dkelly wrote: No reason you couldn't read the injected template XML and modify it instead of creating it from scratch.. Document() creator optional takes a filename of existing XML file to read.
Thanks Dwight - I've ended up using your script and just taking it as job ticket info - all I need do is add variables to that as well as the XML (i.e. from iDropper source) - it works well.
It gives me a basis I have for the 100 odd new ideas rattling around inside my brain....
Edit: One small issue occurring now - I cannot get the jobticket info into my template:
A notification has been passed to [Metadata.Text:Path="/XMLSTINGRAYInJobReport/CSR_First",Dataset="Xml",Model=XML][Metadata.Text:Path="/jobInfo/CSR_First",Dataset="Xml",Model=XML][Metadata.Text:Path="/jobInfo/CSR_First",Dataset="jobticket",Model=XML] [Metadata.Text:Path="/jobInfo/CSR_Last",Dataset="Xml",Model=XML][Metadata.Text:Path="/jobInfo/CSR_Last",Dataset="jobticket",Model=XML][Metadata.Text:Path="/XMLSTINGRAYInJobReport/CSR_Last",Dataset="Xml",Model=XML] who will be your contact within Ashford Colour Press.
As you can see - I have 3 different potential sources, only 1 of which will ever be used.
[Metadata.Text:Path="/XMLSTINGRAYInJobReport/CSR_First",Dataset="Xml",Model=XML]
and
[Metadata.Text:Path="/jobInfo/CSR_First",Dataset="Xml",Model=XML]
work fine, however:
[Metadata.Text:Path="/jobInfo/CSR_First",Dataset="jobticket",Model=XML]
Doesn't....
Most perplexing. Any suggestions anyone?
Extract from XMP and insert into XML
Posted: Thu Apr 12, 2012 9:39 am
by Clive Andrews
Is it because the dataset needs to be XML to use in my HTML template...?