Copy link to clipboard
Copied
How to save a file using the folder name? In the below code i want to replace the "test" with my source PDF folder name. How to do that?
newDoc.saveAs("/c/temp/test.xlsx", "com.adobe.acrobat.xlsx");
If the source is the current pdf then you just split the folder path and extract the last folder name.
Here's an article that shows a technique for manipulating path elements:
https://acrobatusers.com/tutorials/splitting-and-rebuilding-strings
If you know the source PDF, then you know the folder. The full path to the PDF is a document property, as shown in the article.
Copy link to clipboard
Copied
Do you mean that you want to use the file's current folder? If so, then use this code:
newDoc.saveAs(newDoc.path.replace(newDoc.documentFileName, "text.xlsx"), "com.adobe.acrobat.xlsx");
Copy link to clipboard
Copied
No Try, I want to save the excel file in the name of my source pdf folder. For example my source pdf folder path is c/MyDocs/mysource.pdf. I want to save the excel file with name as MyDocs.xlsx instead of test.xlsx
Copy link to clipboard
Copied
I don't understand what you mean... What is this "source file"? Do you have a variable referencing it?
Copy link to clipboard
Copied
Can't be done. Acrobat JavaScript is sandboxed, meaning that it's very limited when it comes to anything that touches the user's file system. There are no general file system commands.
Copy link to clipboard
Copied
Extract the name from newDoc.path
Copy link to clipboard
Copied
Could you please give me some idea how to do this? Instead of the file name as Test i want MyDocs as my file name while saving(which is mySource pdf folder name)
var newDoc = app.newDoc();
newDoc.insertPages( {
nPage: -1,
cPath: "/C/MyDocs/mySource.pdf",
nStart: 2,
nEnd: 3
});
newDoc.saveAs("/c/Temp/Test.xlsx", "com.adobe.acrobat.xlsx");
newDoc.closeDoc(true);
Copy link to clipboard
Copied
Ok, so you want to save the pdf in "newDoc" as an xlsx file, but named for the folder of your source PDF. So what is your source PDF? In the code above it's hard coded, so you already know this? Or is the source PDF the current document? How do you know what the source PDF is? If you already know it at the time the code is written then just use the name in the code.
newDoc.saveAs("/c/Temp/mySource.xlsx", "com.adobe.acrobat.xlsx");
Copy link to clipboard
Copied
Thanks Thom for your reply. If the source PDF is current document then how to proceed?. In case if i don't know my source PDF folder how to proceed on this?
Copy link to clipboard
Copied
If the source is the current pdf then you just split the folder path and extract the last folder name.
Here's an article that shows a technique for manipulating path elements:
https://acrobatusers.com/tutorials/splitting-and-rebuilding-strings
If you know the source PDF, then you know the folder. The full path to the PDF is a document property, as shown in the article.
Copy link to clipboard
Copied
Finally i did it. BTW Great tutorial Thom. Very easy to understand. Thank you.
Copy link to clipboard
Copied
Try this:
var oldDoc = this;
// rest of code goes here
newDoc.saveAs(oldDoc.path.replace(oldDoc.documentFileName, "text.xlsx"), "com.adobe.acrobat.xlsx");
Copy link to clipboard
Copied
madhusudhananc wrote
Could you please give me some idea how to do this? Instead of the file name as Test i want MyDocs as my file name while saving(which is mySource pdf folder name)
var newDoc = app.newDoc(); newDoc.insertPages( { nPage: -1, cPath: "/C/MyDocs/mySource.pdf", nStart: 2, nEnd: 3 }); newDoc.saveAs("/c/Temp/Test.xlsx", "com.adobe.acrobat.xlsx"); newDoc.closeDoc(true);
Info: On a Windows system the path of the new document is something like this:
/C/Users/{user}/AppData/Local/Temp/A9Rohkewh_1khr97d_8do.tmp