Skip to main content
Participant
February 6, 2024
Question

JavaScript, Saving, temp file

  • February 6, 2024
  • 2 replies
  • 791 views

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

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
February 6, 2024

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);

Thom Parker
Community Expert
Community Expert
February 6, 2024

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. 

  

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often