Copy link to clipboard
Copied
How its possible, using javascript, to read some information from pdf with xmp metada (I think it's an xmp metadata, but maybe I'm wrong since I don't have much experience with these files).
I have some pdf template files and they have some information imortant for me. Could you help me how to read information for vsize hsize from this document, using javascript? Thanks in advanced
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.1.2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:egGr="http://ns.esko-graphics.com/"
xmlns:egInk="http://ns.esko-graphics.com/">
<egGr:nrpages>1</egGr:nrpages>
<egGr:startlogpage>1</egGr:startlogpage>
<egGr:units>mm</egGr:units>
<egGr:vsize>120</egGr:vsize>
<egGr:hsize>120</egGr:hsize>
<egGr:margtop>20</egGr:margtop>
<egGr:margbot>10</egGr:margbot>
<egGr:margleft>20</egGr:margleft>
<egGr:margright>20</egGr:margright>
<egGr:readerspread>False</egGr:readerspread>
<egGr:screenreg>False</egGr:screenreg>
</rdf:Description>
</x:xmpmeta>
OK, I finally have it working, based on the script from jazz-y and another one from the Illustrator forum... For an open file:
#target photoshop
var ns = "http://ns.esko-graphics.com/grinfo/1.0/";
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
xmpMeta = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
var theValue = xmpMeta.getProperty(ns, "vsize");
alert(theValue);
Here is a visual of the XMP metadata and how it relates to the code:
P.S. The p
...Copy link to clipboard
Copied
XMP files are plain text. You just need to parse it to get your data. Extendscript/ScriptUI has built-in XML/XMP tools or you can do it yourself.
https://developer.adobe.com/creative-cloud/#api-list
I have a demo on how to work with XML data on my dropbox, and many of my scripts deal with XMP data.
https://www.dropbox.com/sh/mg817g9a9ymbasi/AADTmXUVxmFfM58bcyYE7yiwa?dl=0
Copy link to clipboard
Copied
I would think that one would need to use BridgeTalk or some other method to *directly* get the XMP metadata out of the PDF and do something with it in Photoshop, as once you rasterize the PDF that metadata would be lost (or so I'm assuming).
Edit: I have just pulled a customer file out of the archive that was processed by Esko Automation Engine, and lo and behold, when rasterizing the PDF into Photoshop – the Esko metadata is retained (much to my surprise)!
Copy link to clipboard
Copied
Hmmm... i just need to read this specific attribute and use that value later in PS script, i dont need to import pdf into PS. I had similar issue with XML and it s resolved, but now i am stucked. I dont know how to read those egGR tags.
Copy link to clipboard
Copied
My script example shows you how to read individual values.
Copy link to clipboard
Copied
Here is an example of reading XMP from a file or from an opened document from jazz-y:
I think you would need to get it from the file, not the opened document. Without access to a sample PDF file containing this Esko metadata, I can't test or offer direct assistance.
Edit: Another couple of examples –
https://community.adobe.com/t5/photoshop-ecosystem-discussions/get-print-dpi-resolution/m-p/10502703
Copy link to clipboard
Copied
OK, I finally have it working, based on the script from jazz-y and another one from the Illustrator forum... For an open file:
#target photoshop
var ns = "http://ns.esko-graphics.com/grinfo/1.0/";
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
xmpMeta = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
var theValue = xmpMeta.getProperty(ns, "vsize");
alert(theValue);
Here is a visual of the XMP metadata and how it relates to the code:
P.S. The previous example parses the XML value as a string, you may need to convert it to a number if you need to perform mathematical operations on the value, again, for an open file:
#target photoshop
var ns = "http://ns.esko-graphics.com/grinfo/1.0/";
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
xmpMeta = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
var theValue = Math.abs(xmpMeta.getProperty(ns, "vsize"));
alert(theValue);
Edit: Via a hard-coded path:
#target photoshop
var f = new File('~/Desktop/esko-art-sample.pdf');
var ns = "http://ns.esko-graphics.com/grinfo/1.0/";
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
xmpMeta = new XMPFile(f.fsName, XMPConst.FILE_PDF, XMPConst.OPEN_FOR_READ).getXMP();
var theValue = Math.abs(xmpMeta.getProperty(ns, "vsize"));
alert(theValue);
Via an open dialog:
#target photoshop
var f = File.openDialog();
var ns = "http://ns.esko-graphics.com/grinfo/1.0/";
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
xmpMeta = new XMPFile(f.fsName, XMPConst.FILE_PDF, XMPConst.OPEN_FOR_READ).getXMP();
var theValue = Math.abs(xmpMeta.getProperty(ns, "vsize"));
alert(theValue);
Copy link to clipboard
Copied
Thank you all, for your commitment, this is really good job.
@Stephen Marsh thanks a lot
Copy link to clipboard
Copied
@Stephen Marsh could you help me with this one. I have an jdf file with xml listed bellow, but i stuck, how to read "value" for "job"?
<?xml version="1.0" encoding="UTF-8"?>
<JDF xmlns="http://www.CIP4.org/JDFSchema_1_1" xmlns:eg="http://www.esko-graphics.com/EGSchema1_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Product">
<eg:SmartName Name="Job" Value="Poland_001"/>
<eg:SmartName Name="Barcode" Value="Yes"/>
<eg:SmartName Name="Separation" Value="CMYK"/>
<eg:SmartName Name="Paper_grade" Value="300g"/>
<eg:SmartName Name="Template" Value="Template_box"/>
</JDF>
Copy link to clipboard
Copied
I tried to find a solution in the scripts that @Lumigraphics shared, but i got empty message.
What is wrong in my code?
var XMLfile = new File("/Users/rsmilevicm/Documents/test.jdf");
XMLfile.open('r');
var str = "";
str = XMLfile.read();
XMLfile.close();
var xml = new XML(str);
default xml namespace = "http://www.esko-graphics.com/EGSchema1_0";
var job_name = xml.data.(@Name == 'Job').@value;
alert(job_name)
Copy link to clipboard
Copied
Make sure you are casting your data types, so job_name.toString() as an example.
I don't know what that schema defines so there isn't a way to know if your usage is correct.
Copy link to clipboard
Copied
Sorry, no luck with the JDF, perhaps a more knowledgeable scripter can post working code...
Copy link to clipboard
Copied
I finally resolved this. Maybe it will be useful for someone.
var XMLfile = new File("/Users/rsmilevicm/Documents/test.jdf");
XMLfile.open('r');
var str = "";
str = XMLfile.read();
XMLfile.close();
var xml = new XML(str);
default xml namespace = "http://www.esko-graphics.com/EGSchema1_0";
var job_name = xml.xpath("//*[@Name = 'Job']/@Value");
alert(job_name)
Copy link to clipboard
Copied
@milevic - fantastic! Thank you for coming back and sharing with the community!
Copy link to clipboard
Copied
Dear @Stephen Marsh could you help me with this data? I want to read all colors and their angles, but i am stucked...
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.1.2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:egGr="http://ns.esko-graphics.com/"
xmlns:egInk="http://ns.esko-graphics.com/">
<egGr:nrpages>1</egGr:nrpages>
<egGr:startlogpage>1</egGr:startlogpage>
<egGr:units>mm</egGr:units>
<egGr:vsize>120</egGr:vsize>
<egGr:hsize>120</egGr:hsize>
<egGr:margtop>20</egGr:margtop>
<egGr:margbot>10</egGr:margbot>
<egGr:margleft>20</egGr:margleft>
<egGr:margright>20</egGr:margright>
<egGr:readerspread>False</egGr:readerspread>
<egGr:screenreg>False</egGr:screenreg>
<egGr:inks>
<rdf:Seq>
<rdf:li rdf:parseType="Resource">
<egInk:name>Cyan</egInk:name>
<egInk:frequency>320</egInk:frequency>
<egInk:angle>15</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>Magenta</egInk:name>
<egInk:frequency>320</egInk:frequency>
<egInk:angle>30</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>Yellow</egInk:name>
<egInk:frequency>320</egInk:frequency>
<egInk:angle>45</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>Black</egInk:name>
<egInk:frequency>320</egInk:frequency>
<egInk:angle>75</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
</rdf:li>
</rdf:Seq>
</rdf:Description>
</x:xmpmeta>
I tried just to read angle with code bellow, but i got NaN alert. I am not sure how to read an array of those nested values
var ns = "http://ns.esko-graphics.com/grinfo/1.0/";
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
xmpMeta = new XMPFile(f.fsName, XMPConst.FILE_PDF, XMPConst.OPEN_FOR_READ).getXMP();
var theValue = Math.abs(xmpMeta.getProperty(ns, "angle"));
alert(theValue);
Copy link to clipboard
Copied
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more