Copy link to clipboard
Copied
app.document.deselectAll();
var count = app.document.visibleThumbnailsLength;
app.synchronouseMode=true;
for ( var i = 0; i < count; i++ ) {
if ( app.document.visibleThumbnails[i].name.indexOf("-lr")==-1&&app.document.visibleThumbnails[i].name.split(".")[1]=="pdf") {
var selectedFile = app.document.visibleThumbnails[i].spec;
app.document.select( app.document.visibleThumbnails[i] );
var thumbnailMeta=app.document.visibleThumbnails[i].metadata;
//var addIPTC_Core=thumbnailMeta.applyMetadataTemplate ("Imaging_Template_1.0","append");
$.writeln(thumbnailMeta)
if (ExternalObject.AdobeXMPScript == undefined){
ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
}
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
So if I use this library I am only able to write to this file if that schema exists. Right now I have a PDF that just has some custom metatdata and I want to add some ITPC_Core metat data to it but That schema doesn't exist. So I either need to figure out how to write to the custom schema or create a new ITPC_Core schema and then edit that. Any help is appreciated.
function setXMPValue (xmpType,propertyValid,propertyToSet,propertyValue,propertyFlag){
// var Email = myXmp.getStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo",XMPConst.NS_IPTC_CORE, "CiEmailWork");///gets the value of the structure
try{
if(propertyValid){
myXmp.setArrayItem(xmpType, propertyToSet,1,propertyValue);
}
else{
if(propertyFlag=="field"){
//if the property is nested and does not exists already we have to setStructField which requires a different constructor
var setAField= myXmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo",XMPConst.NS_IPTC_CORE, "CiEmailWork",propertyValue);///sets the value of the structure for field
}
else{
myXmp.appendArrayItem(xmpType, propertyToSet, propertyValue, 0, XMPConst.PROP_IS_ARRAY);
}
}
}
catch(err){
$.writeln(err)
}
}
Copy link to clipboard
Copied
myXmpFile.canPutXMP(myXmp)
This is returning false unless I add something in the metadata tab. How do I do this automatically?
Copy link to clipboard
Copied
var thumbnailMeta=app.document.visibleThumbnails[i].metadata; $.writeln("/// "+thumbnailMeta.hasMetadata)
This returns nothing. I would think it would return true or false but i get nothing.
Copy link to clipboard
Copied
There should be no problem writing IPTC data if not existed, just tested it on a newly created PDF and all details were entered.
#target bridge;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
//For test pupose use the first selected file
var selectedFile = app.document.selections[0].spec;
var xmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var xmp = xmpFile.getXMP();
try {
xmp.appendArrayItem( XMPConst.NS_DC, "creator", "Creator", 0, XMPConst.ARRAY_IS_ORDERED );
xmp.setLocalizedText( XMPConst.NS_DC, "title", null, "en-US", "Title" );
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "AuthorsPosition", "Author Position");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Headline", "Headline");
xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", "Caption/Description" );
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "DateCreated", new XMPDateTime(new Date()), XMPConst.XMPDATE);
var Keys=["Keyword1","Keyword2","Etc."];
for(var s in Keys){
xmp.appendArrayItem(XMPConst.NS_DC, "subject", Keys[s], 0,XMPConst.PROP_IS_ARRAY);
}
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrCtry", "England" );
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiEmailWork", "Joe.Bloggs@email.com" );
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrCity","Leeds");
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrExtadr","Address");
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrPcode","LS12PP");
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrRegion","West Yorkshire");
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiTelWork","0132999999");
xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiUrlWork","<a href="http://www.mysite.co.uk" target="_blank">www.mysite.co.uk</a>");
xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:Location","Sub Location");
xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:IntellectualGenre","Itellectual Genre");
xmp.appendArrayItem( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode","IPTC Subject Code",0,XMPConst.PROP_IS_ARRAY);
xmp.appendArrayItem( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:Scene","IPTC Scene Code",0,XMPConst.PROP_IS_ARRAY);
xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:CountryCode", "ISO Country Code" );
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "City", "London");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "State", "State/Province");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Country", "Britain");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "CaptionWriter", "Description Writer");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "TransmissionReference", "Job Identifier");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Instructions", "Instructions");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Credit", "Credit Line");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Source", "Source");
xmp.setLocalizedText( XMPConst.NS_DC, "rights", null, "x-default", "Copyright Notice" );
xmp.appendArrayItem( XMPConst.NS_XMP_RIGHTS, "UsageTerms","Rights Usage",0,XMPConst.PROP_IS_ARRAY);
xmp.setProperty( XMPConst.NS_XMP_RIGHTS, "Marked",true, XMPConst.STRING); //true = copyright, false = public domain if( xmpFile.canPutXMP( xmp ) )
{
xmpFile.putXMP(xmp);
}
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
} catch( e ) {
$.writeln("ERROR SETTING METADATA: \n" + e + "\n"+e.line );
}
Copy link to clipboard
Copied
You need to clean this up, you have typos and missing semicolons.
visibleThumbnails doesn't always work well, app.document.thumbnail.children is more reliable in my experience.
You might have better luck with this namespace:
xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/"
You can also try thumbnail.mimeType to determine what kind of file you have. A PDF returns "application/pdf"
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now