JavaScript, Saving, temp file
Copy link to clipboard
Copied
Dear friends,
I need to edit a PDF file in Acrobat Reader and save it afterwards under the same name and location. The file is called by a DMS-App as a temp-file. I wrote a code for saving and closing:
// Meue Item
app.addMenuItem( { cName: "mySaveDoc", cUser: "Direktspeichern",
cParent: "File", cExec: "mySaveDoc(this, this.path)",
cEnable: "event.rc = (app.doc != null);",
nPos: "Open", bPrepend: true } );
//Function for saving the doc
var mySaveDoc = app.trustedFunction(function(oDoc, myPath){
app.beginPriv();
oDoc.saveAs({cPath: myPath, bPromptToOverwrite: false});
oDoc.closeDoc(true);
app.endPriv();
});
The code works fine but not for the temp-files, I get a message of ‚write protection / doc used by onother user‘. But I can navigate to the temp-file in the „Save As“ dialog box and save it manually without any problems.
Please, could you give me advice what I could try?
Thanks, Markus
Copy link to clipboard
Copied
If this file is a "temp" file, then does it have a ".tmp" file extension? If so, the doc.saveAs() function will have a problem with it. You'll need to change the extension if this is the case.
Also, not all file paths are equal. There are restrictions on access. Read this:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html#safe-path
Some restrictions are based on security settings. You may be able to override a restriction by making the temp location trusted.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
If the file is temporary you need to prompt the user to save it first as a full PDF file.
You can do it like this:
if (this.requiresFullSave) app.execMenuItem("SaveAs");
else mySaveDoc(this, this.path);

