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

Saving Document in Folder Name

Explorer ,
Jan 04, 2018 Jan 04, 2018

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

793

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 05, 2018 Jan 05, 2018

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.

Votes

Translate

Translate
Community Expert ,
Jan 04, 2018 Jan 04, 2018

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

Votes

Translate

Translate

Report

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
Explorer ,
Jan 04, 2018 Jan 04, 2018

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

Votes

Translate

Translate

Report

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 ,
Jan 04, 2018 Jan 04, 2018

Copy link to clipboard

Copied

I don't understand what you mean... What is this "source file"? Do you have a variable referencing it?

Votes

Translate

Translate

Report

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 ,
Jan 04, 2018 Jan 04, 2018

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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Jan 04, 2018 Jan 04, 2018

Copy link to clipboard

Copied

Extract the name from newDoc.path

Votes

Translate

Translate

Report

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
Explorer ,
Jan 04, 2018 Jan 04, 2018

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

Votes

Translate

Translate

Report

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 ,
Jan 04, 2018 Jan 04, 2018

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Jan 05, 2018 Jan 05, 2018

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?

Votes

Translate

Translate

Report

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 ,
Jan 05, 2018 Jan 05, 2018

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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Jan 05, 2018 Jan 05, 2018

Copy link to clipboard

Copied

LATEST

Finally i did it. BTW Great tutorial Thom. Very easy to understand. Thank you.

Votes

Translate

Translate

Report

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 ,
Jan 05, 2018 Jan 05, 2018

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

Votes

Translate

Translate

Report

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 ,
Jan 05, 2018 Jan 05, 2018

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

Votes

Translate

Translate

Report

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