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

Document.save() for old documents created in 2019 not works in InDesign Server CC2021

Community Beginner ,
Mar 23, 2022 Mar 23, 2022

Copy link to clipboard

Copied

Hi All,

 

In our workflow we had some old documents created in year 2019.

Now when we opened those documents in 'InDesign Server CC 2021' and try to save the document with code

var objFile = File(strDocPath);
if(objFile.exists) {
    objDoc = app.open(strDocPath);

}

 

if(objDoc)
{
      if(!objDoc.saved) {
        objDoc.save(File(strDocPath));
      }
}
 
then it set the document size as 0 (zero).
 
Does anyone experienced such thing.
 
Let me know what could be the reason of it.
 
InDesign Server Version CC 2021 (16.4)
Mac OSX 10.14.6, Intel based.
 
Regards,
Alam
 
 

 

Regards,

Alam

TOPICS
Scripting

Views

177

Likes

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
Community Expert ,
Mar 23, 2022 Mar 23, 2022

Copy link to clipboard

Copied


@Alam5EC6 wrote:
then it set the document size as 0 (zero).

 

Yikes! So it basically destroys the file?! I'm not experienced with Indesign Server, but while we wait for an expert, you could try changing the line

objDoc.save(File(strDocPath));

to

objDoc.save(File(strDocPath.replace(/\.indd/, '_test.indd')));

This will just save the .indd document with "_test" suffix, just to see if the test file also is zero size.

- Mark

Likes

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
Community Beginner ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

Hi Mark

 

After following your steps I see two files in my working folder one with originol name and other with _test name.

But I need one file in my working folder.

 

Do you have any other solution?

 

Regards,

Alam

Likes

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
Community Expert ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

Hi @Alam5EC6, sorry I wasn't offering a solution—that was just a test to see if the 2nd file (the one with _test) had zero size. In other words does the problem you are having go away if you save into a new file vs saving into the same file? Can you check and let us know?

Because I have no idea what's happening for you I am trying to help you troubleshoot. That's all. Let me know the result.

- Mark

Likes

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
Community Beginner ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

Yes the problem of 0 size has gone way after following your steps

Likes

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
Community Expert ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

Hi Alam,

if both files of Mark's solution are ok with you, you could remove the old one and rename the new one.

It's a workaround, yes. But what would you like to do?

 

Perhaps you could open a copy of the file and work with that?

 

var newDocument = app.open( strDocPath , OpenOptions.OPEN_COPY  );
newDocument.save( File(strDocPath));

 

Don't know if that will change something for you.

Have not InDesign Server installed.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Community Beginner ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

Hi Uwe,

 

I am doing following with open file

if(objDoc)
{
        if(!objDoc.saved)
              objDoc.save(File(strDocPath));
 
    // setUnitToMillim
   // generateFontReport
// return docId to java BE to execute other scripts for further workflow and other scripts expect docId instead of document path
 
Regards,
Alam
}

 

Regards,

Alam

Likes

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
Community Expert ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

What do you mean exactly by docId  ?

Wouldn't that be a value you could also apply to the saved duplicate of the document?

( Here I assume, that you perhaps identify a document by the value of a label you set with insertLabel("key string","value string") . )

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Community Beginner ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

objDoc = app.open(docPath);

docId = objDoc.id

 

Regards,

Alam

Likes

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
Community Expert ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

Hm. By far this is not a unique id.

Close a document, open it again and you'll see a new number for the same document.

 

Regards,
Uwe Laubender

( ACP )

 

 

Likes

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
Community Beginner ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

LATEST

Correct, but our workflow use this approach to work with document.

I solved my problem by saving document with different name, close it.

delete the old document.

rename test file with actual docName

open the document again.

 

Thanks all for thier valueable suggestion

Likes

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
Community Expert ,
Mar 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

By the way, I found some code to get (I think) a real document UUID. It seems to work in my quick testing.

/*
    Code by RobC
    from here: https://stackoverflow.com/questions/56289308/need-to-generate-uuid-for-windows-system-in-extendscript
    modified slightly by m1b
    here: https://community.adobe.com/t5/indesign-discussions/document-save-for-old-documents-created-in-2019-not-works-in-indesign-server-cc2021/m-p/12834120)
*/

var docID = getDocumentUUID(app.activeDocument);

/**
 * Generates a unique identifier (UUID/GUID) cross-platforms (macOS/Windows).
 * @Returns {String} - The generated unique identifier.
 */
function getDocumentUUID(doc) {
    if (loadXMPLibrary()) {
        var docFile = File(doc.filePath + '/' + doc.name);
        var xmpFile = new XMPFile(docFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_READ);
        var xmp = xmpFile.getXMP();
        var documentID = xmp.getProperty(XMPConst.NS_XMP_MM, 'DocumentID', XMPConst.STRING);
        return String(documentID).replace(/xmp\.did:/g, '');
    }
}

/**
 * Loads the AdobeXMPScript library.
 * @Returns {Boolean} True if the library loaded successfully, otherwise false.
 */
 function loadXMPLibrary() {
    if (!ExternalObject.AdobeXMPScript) {
        try {
            ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
        } catch (e) {
            alert('Failed loading AdobeXMPScript library\n' + e.message, 'Error', true);
            return false;
        }
    }
    return true;
}

 However, you must test for your use case. For example, when you open document as a copy, it will probably generate a new UUID for that copy—so the method Uwe and I were talking about might change the UUID, but that might be fine if you generate and use the UUID only *after* the open copy/save has happened.

- Mark

Likes

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