Skip to main content
December 3, 2025
Answered

exportAsText works for some paths but returns GeneralError for others

  • December 3, 2025
  • 2 replies
  • 398 views

Hello,

 

I am trying to make a stamp that will save the users input as a .txt file. 

I am using the exportAsText function within a trusted function and it mostly works until I try and save the output to different folders.

 

With the following code the output saves correctly however I don't want to save the result within the DC folder. I have changed my username to [username] in the code snippets for privacy reasons.

 
exportDataTotxt = app.trustedFunction( function(filename){
    app.beginPriv();
    savepath = "C:\\Users\\[username]\\AppData\\Roaming\\Adobe\\Acrobat\\DC\\"+filename;
    this.exportAsText(false,null,savepath);
    app.endPriv();
 });

When I change the savepath variable to the folllowing:

savepath = "C:\\Users\\[usermane]\\"+filename;

I get this error: 

GeneralError: Operation failed.
Doc.exportAsText:5:App Script:Calculate

 

I have tried with a number of different folder locations including in different drives but it only works within the DC folder.

 

For context the filename variable is defined in the stamp's code as follows:

filename = util.printd("ddmmyyyyHHMMss", new Date()) + "_Data.txt";

 

Correct answer Bernd Alheit

Try this:

Disable the protection mode in the preferences of Acrobat.

2 replies

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
December 3, 2025

Try this:

Disable the protection mode in the preferences of Acrobat.

theo_2948Author
December 4, 2025

Thank you. This was the issue

PDF Automation Station
Community Expert
Community Expert
December 3, 2025

According to the documentation the path must be a safe path, which states "A path cannot point to a system critical folder, for example a root, windows or system directory....Generally, when a path is judged to be not safe, a NotAllowedError exception is thrown (see Error object) and the method fails."

I ran quick tests in the console.  The path to the desktop passed but the path to the User/[UserName]/ folder failed.

theo_2948Author
December 3, 2025

I initially thought that was the problem however the API docs say a safe path error should throw a NotAllowedError. Instead I am getting a GeneralError. (I will acknowledge that my understanding of Javascript is quite poor, not to mention Adobe's implimentation of it.)

I just tried my destop (which is inside a onedrive folder) and my downloads (Which is not in a onedrive folder) and both of those failed the same way.

theo_2948Author
December 3, 2025

Addition:

 

I have tried C:\\temp\\ as the docs say this is a 'safe path' however this also fails.