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);
}
Regards,
Alam
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
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
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
Copy link to clipboard
Copied
Yes the problem of 0 size has gone way after following your steps
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 )
Copy link to clipboard
Copied
Hi Uwe,
I am doing following with open file
Regards,
Alam
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 )
Copy link to clipboard
Copied
objDoc = app.open(docPath);
docId = objDoc.id
Regards,
Alam
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 )
Copy link to clipboard
Copied
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
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