Extract from XMP and insert into XML
-
- Member
- Posts: 85
- Joined: Thu Jun 23, 2011 11:41 am
Extract from XMP and insert into XML
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"....
:)
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"....
:)
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Extract from XMP and insert into XML
Apago PDFspy can retrieve XMP for document and/or individual images.
-
- Member
- Posts: 85
- Joined: Thu Jun 23, 2011 11:41 am
Extract from XMP and insert into XML
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....
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....
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Extract from XMP and insert into XML
In that case, you can extract the XMP using Switch, modify it using an XSLT transform and write it back using XMP update.
-
- Member
- Posts: 85
- Joined: Thu Jun 23, 2011 11:41 am
Extract from XMP and insert into XML
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!
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!
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Extract from XMP and insert into XML
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.
-
- Member
- Posts: 85
- Joined: Thu Jun 23, 2011 11:41 am
Extract from XMP and insert into XML
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.
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.
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Extract from XMP and insert into XML
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
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

-
- Member
- Posts: 85
- Joined: Thu Jun 23, 2011 11:41 am
Extract from XMP and insert into XML
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?
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Extract from XMP and insert into XML
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.
-
- Member
- Posts: 85
- Joined: Thu Jun 23, 2011 11:41 am
Extract from XMP and insert into XML
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?
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?
-
- Member
- Posts: 85
- Joined: Thu Jun 23, 2011 11:41 am
Extract from XMP and insert into XML
Is it because the dataset needs to be XML to use in my HTML template...?