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

JavaScript, Saving, temp file

New Here ,
Feb 06, 2024 Feb 06, 2024

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

TOPICS
How to , JavaScript , PDF , Standards and accessibility
606
Translate
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 ,
Feb 06, 2024 Feb 06, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Feb 06, 2024 Feb 06, 2024
LATEST

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

Translate
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