Skip to main content
Participating Frequently
April 20, 2017
Question

Bridge import metadata from .txt - can it work for a pdf?

  • April 20, 2017
  • 2 replies
  • 1211 views

Hello,

Found a great script that will import / update metadata for me, it works really well on my .jpgs but I have several images that are .pdf, and it does not error but does not bring in the metadata. Any suggestions are much appreciated.

Thank you.

    This topic has been closed for replies.

    2 replies

    Stephen Marsh
    Community Expert
    Community Expert
    April 20, 2017

    Looking at these specs, I'm guessing that these fields may not apply to PDF:

    PDF Tags

    EDIT:

    So it is possible to manually enter the metadata using Bridge… so this should be scriptable.

    File > File Info lists this as:

    <dc:description>

                <rdf:Alt>

                   <rdf:li xml:lang=“x-default”>DESCRIPTION TEST ENTERED</rdf:li>

                </rdf:Alt>

    </dc:description>

    While ExifTool lists this as:

    PDF:Subject='DESCRIPTION TEST ENTERED'

    In Acrobat’s properties window, it is also listed in the subject field.

    sms2020Author
    Participating Frequently
    April 21, 2017

    Thank you!

    I will see what I can do

    I did find that if you put a description into the PDF (file properties, additional metadata, description) it does then show up in bridge in the description field. So many scripting the metadata into the PDF instead of through Bridge is one way to accomplish if need be.

    Stephen Marsh
    Community Expert
    Community Expert
    April 23, 2017

    There is obviously something different between the JPG and the PDF as far the script is concerned.

    I tried the original scripts and they too have an issue with updating the PDF, so it was not something that happened when you altered the original script.

    I did have success using ExifTool to embed the required metadata into a PDF file:

    exiftool -XMP-iptcCore:Location='Test Sublocation' -XMP-dc:Description='Test Description' '/Mac OS Path/to/my test file.pdf'

    (This code is formatted for the Mac OS, MS Windows would use straight double quote marks " and the expected \ file path formatting).

    However this test ExifTool command would need to be changed to use a tab delimited .txt or comma separated .csv source file… Let me know if there is any interest. Of note, the same command works for both JPG and PDF files with ExifTool, so it does not appear to have the same limitation as this Bridge script.

    Otherwise you may need to look deeper into the script (sorry, I can’t script, however sometimes I can hack them).

    Stephen Marsh
    Community Expert
    Community Expert
    April 20, 2017

    It would be helpful to know:

    • What metadata fields you are attempting to update
    • The script code or link
    sms2020Author
    Participating Frequently
    April 20, 2017

    I am updating the Description and Location fields. The script is on ps-scripts.com (in the archives Bridge import keywords from CSV ) DescriptionLocationHeadlineDateII.jsx. There is one on there for csv, this one is for a txt file, it has the II in the name). I slightly modified the original script, I only need the Desc and Location, so deleted the Headline and Date.

    #target bridge  

       if( BridgeTalk.appName == "bridge" ) { 

    metaFRomTEXT = MenuElement.create("command", "Add Metadata from TEXT file", "at the end of Thumbnail");

    }

    metaFRomTEXT.onSelect = function () {

       updateMetadataTXT();

       }

     

    function updateMetadataTXT(){

    var Path =app.document.presentationPath;

    var errorLog = File(Path +"/Error Log.txt");

    loadXMPLib();

    var descFile = File.openDialog("Open Metadata File","TEXT File(*.txt):*.txt;");

    if(descFile == null) return;

    descFile.open('r');

    descFile.readln(); //Un-comment  this line to remove header line.

    var datFile=[];

    while(!descFile.eof){

    var line = descFile.readln();

    line=line.replace(/\"/g,'');

    if(line.length > 5) datFile.push(line);

      }

    descFile.close();

    errorLog.open('w');

    errorLog.writeln("Processing :: "+decodeURI(descFile.fsName) +" Total Files = "+datFile.length+"\r\r");

    errorLog.close();

    for(var t in datFile){

    var str=datFile;

    str= str.split('\t');

    var fileName = File(Path+"/"+ str.shift());

    var Desc = str.shift().toString().replace(/\"/g,'');

    var Location = str.shift().toString().replace(/\"/g,'');

    if(fileName.exists){

    var thumb = new Thumbnail(fileName);

       if(thumb.hasMetadata){

          var selectedFile = thumb.spec;   

          try{

          var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 

          }catch(e){sendError(errorLog,decodeURI(fileName)+ " :: unable to open file for update");}

          var myXmp = myXmpFile.getXMP();  

         

            try{

            myXmp.deleteProperty(XMPConst.NS_DC, "description");

            myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );

            }catch(e){sendError(errorLog,decodeURI(fileName)+ " :: Bad Description : "+Desc);}

           

            try{

            myXmp.deleteProperty(XMPConst.NS_IPTC_CORE, "Location");

            myXmp.setProperty(XMPConst.NS_IPTC_CORE, "Location",Location);

            }catch(e){sendError(errorLog,decodeURI(fileName)+ " :: Bad Location : "+Location);}

           

          if (myXmpFile.canPutXMP(myXmp)) {

              try{

                myXmpFile.putXMP(myXmp);

                myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

                }catch(e){sendError(errorLog,decodeURI(fileName)+ " :: unable to update : " +e);}

             }

          }

    }else{

    errorLog.open('e');

    errorLog.seek(0,2);

    errorLog.writeln(decodeURI(fileName) + " does not exist!");

    errorLog.close();

    }

    }

    unloadXMPLib();

    errorLog.execute();

    }

    function sendError(errorLog,errorMessage){

    errorLog.open('e');

    errorLog.seek(0,2);

    errorLog.writeln(errorMessage);

    errorLog.close();

        }

    function loadXMPLib(){

    if (ExternalObject.AdobeXMPScript == undefined) {

        ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

      }

    }

    function unloadXMPLib(){

       if( ExternalObject.AdobeXMPScript ) {

          try{

             ExternalObject.AdobeXMPScript.unload();

             ExternalObject.AdobeXMPScript = undefined;

          }catch (e){ }

       }

    }