Skip to main content
JavaMan
Participant
March 1, 2026
質問

SaveAs function

  • March 1, 2026
  • 返信数 1.
  • 33 ビュー

I’m trying to use Javascript to extract and save the first two pages of a document, and save that new document in the same folder as the main file. But I’m having trouble whenever the folder name contains a comma. Is there any workaround? Unfortunately removing the commas in the folder name isn’t an option. Script I’m using below:

 

try {
    var doc = this;
    var srcPath = doc.path;
    var folderPath = srcPath.substring(0, srcPath.lastIndexOf("/"));
    var baseName = "Document.pdf";
    var newPath = folderPath + "/" + baseName;

    var newDoc = doc.extractPages({
        nStart: 0,
        nEnd: 1
    });

    newDoc.saveAs({ cPath: newPath });
    newDoc.closeDoc();
}

    返信数 1

    ls_rbls
    Community Expert
    Community Expert
    March 12, 2026

    Hi ​@JavaMan ,

     

    Just to rule out privilege context issues, Does your script work well and not throw any security restriction errors like : “NotAllowedError: Security settings prevent access to this property or method.”  What errors (if any ) are showing up in the console? 

     

    See here: How to Save a PDF with Acrobat JavaScript

     

    Additionally, from what I’ve read recently the saveAs() method would not allow for a folder path name that contains commas in the script.

     

    For additional insights, I found this topic though: Can javascript detect commas in path folder? | Community