Skip to main content
JavaMan
Participant
March 1, 2026
Question

SaveAs function

  • March 1, 2026
  • 0 replies
  • 4 views

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