• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Which Illustrator version created the document?

Contributor ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

Hi,

Using scripting, I need to know which version of Illustrator created an ai or pdf-file.

In this community I found the code below (I tweaked it a bit)...

 

var myPath = "/Users/me/Desktop/artwork.pdf";
var myFile = new File(myPath);

var docVersion = getDocumentVersion(myFile);
var appVersion = getApplicationVersion();

function getApplicationVersion(){
    var resultArr = app.version.split(".");
    return (resultArr[0]);
}


function getDocumentVersion(_myFile){
    var vrs = null;
    _myFile.open("r");

    try{
        while(_myFile.tell() < _myFile.length) {
            var line = _myFile.readln();
            var idxOf = line.indexOf("Creator: Adobe Illustrator(R)");
            if(idxOf > 0) { 
                vrs = line.substring(idxOf+30, line.length);
            }
        }
    }

    catch(ex) {}
    finally { _myFile.close(); }

    if(vrs != null){
        var vrsArr = vrs.split(".");
        vrs = vrsArr[0];
    }

    return vrs; 
}

 

Unfortunately, the version number does not match the application version.

The value returned is 24, but the app version is 27 (CC2023).

 

How can I fix this?

 

Thanx

TOPICS
Scripting

Views

819

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Mar 03, 2023 Mar 03, 2023

Yes, that is correct. Here's a revision on @tmmls's original `getDocumentVersion()` that just reads the raw file data and extracts the correct version string from the `<xmp:CreatorTool>` tag without opening the file in Ai.

 

function getDocumentVersion(_myFile) {
  var vrsString = null;
  var vrs = null;
  _myFile.open("r");

  try {
    while (_myFile.tell() < _myFile.length) {
      var line = _myFile.readln();
      if (line.indexOf("<xmp:CreatorTool>") >= 0) {
        vrsString = line;
       
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

Here's a way to grab the info using the document's XMP data. I tried it with a handful of different file types and it seems to work pretty well, Take it for a spin and let me know if you have any issues. Cheers!

 

var ver = getIllustratorVersion();

/**
 * Extract the Adobe Illustrator version from a documents XMP Data.
 */
function getIllustratorVersion() {
  // Set up some variables
  var xmp, xmpString, aiVersion, splitString;

  // Load the XMP library as an ExtendScript ExternalObject via the docs
  // https://extendscript.docsforadobe.dev/scripting-xmp/index.html
  if (ExternalObject.AdobeXMPScript == undefined)
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

  //Read XMP string - You can see document XMP info in Illustrator @ File > File Info > Raw Data
  var xmp = new XMPMeta(app.activeDocument.XMPString);

  // Grab the CreatorTool property
  try {
    var xmpString = xmp.getProperty(XMPConst.NS_XMP, "xmp:CreatorTool").value;
    // Should give you something like 'Adobe Illustrator 27.2 (Windows)'
    // or `Adobe Illustrator CC 22.0 (Macintosh)`
  } catch (e) {
    alert("Creator Tool Not Found!\n" + e);
    return -1;
  }

  // If file was created by an app other than Illustrator
  if (xmpString.toLowerCase().indexOf("illustrator") < 0) {
    alert("File not created by Adobe Illustrator.");
    return -1;
  }

  // Parse out the actual version number in the string
  // It's more work than it should be because of inconsistent version naming
  splitString = xmpString.split(" ");
  for (var i = 0; i < splitString.length; i++) {
    aiVersion = Number(splitString[i]);
    if (aiVersion) break;
  }

  // Show the results for debugging
  alert("Ai Version Info\nXMP String: " + xmpString + "\nParsed Version: " + aiVersion);

  return aiVersion;
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

However, it requires an open document to read XMP. When we process a folder of files, we need to write the opening and closing of each file =(

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

Yes, that is correct. Here's a revision on @tmmls's original `getDocumentVersion()` that just reads the raw file data and extracts the correct version string from the `<xmp:CreatorTool>` tag without opening the file in Ai.

 

function getDocumentVersion(_myFile) {
  var vrsString = null;
  var vrs = null;
  _myFile.open("r");

  try {
    while (_myFile.tell() < _myFile.length) {
      var line = _myFile.readln();
      if (line.indexOf("<xmp:CreatorTool>") >= 0) {
        vrsString = line;
        break;
      }
    }
  } catch (ex) {
  } finally {
    _myFile.close();
  }

  if (vrsString != null) {
    var splitString = vrsString.split(" ");
    for (var i = 0; i < splitString.length; i++) {
      if (!isNaN(splitString[i])) vrs = splitString[i];
    }
  }

  return vrs;
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

LATEST

Thank you very much for the great response...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines