Solved

JavaScript loop through directory, get filenames

Posted on 2011-09-07
12
2,640 Views
Last Modified: 2012-05-12
I am using AcroJS (adobe acrobat javascript) to load a file from my computer into acrobat reader.  However, I want to load all PDF files in a directory.  Is there anyway to do this?  Perhaps something like this will help you understand what I'm after:

app.openDoc("/w/Ametek/catalogfiles.ametektip.com/Generated/Catalogs/5/cn/"+ * + ".pdf");

(where * is the wildcard, allowing any filename to be selected)

Ideally, I would like to loop through the entire directory and get all PDF files; but I don't know if that's possible...
var myOpen = app.trustedFunction(
    function()
    {
        try {
			app.openDoc("/w/Ametek/catalogfiles.ametektip.com/Generated/Catalogs/5/cn/"+);
		} catch (e) {
			app.alert('err')
		};
	});
	myOpen();

Open in new window

0
Comment
Question by:EMB01
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 7

Assisted Solution

by:Gewgala
Gewgala earned 150 total points
ID: 36500886
I don't think this is possible because it seems it would violate security restrictions.  Javascript can't do any kind of directory browsing.  You could guess, using a regex wild card like you say, but that would take so much computer power because you would in theory be trying to match every single character combination for a file.  You have to guess, you can't be given a list of files, so you're trying to guess every combination from a file with 1 character to a file with whatever the limit the OS puts on file name lengths.  
0
 
LVL 7

Expert Comment

by:Gewgala
ID: 36500887
What you would have to do, is get the list of files on the server.  If you are using PHP or ASP.NET or something like that, you can get a list of files in the desired directory, and then write them out to a javascript array.  You could then iterate through the array in your javascript code and that should work fine.  I don't think you can do this without some kind of server interaction though.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 36500899
This is Adobe PDF specific scripting, nothing to do with a web browser...
0
 
LVL 7

Expert Comment

by:Gewgala
ID: 36500909
Oh.  I thought it was some kind of embedded adobe reader in a web page.  My mistake.
0
 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 100 total points
ID: 36500939
I haven't tested this, only looking through the api for you...
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf

But the Search object might work, search for documents that contain "Acrobat"
search.docInfo = true;
search.query("Acrobat","Folder","/c/myDocuments");

Open in new window

0
 
LVL 14

Author Comment

by:EMB01
ID: 36502116
>>  But the Search object might work, search for documents that contain "Acrobat"

Thanks, that gets me closer.  But, I think I'm going to just feed it the direct filenames since I know what they should be.

Basically, I have an acrobat action that saves all selected documents from PDF to POSTSCRIPT.  I want to make the process even more automated.

Is it possible to run acrobat automatically, say, once a day?  Or, is it possible to run an acrobat action automatically?  I want these files in this directory to be converted to POSTSCRIPT automatically, instead of having to open acrobat and click "run js" and selecting all the files...

Thanks for your help.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 250 total points
ID: 36502501
No, you cannot run an Acrobat process automatically, but have you looked into running your action on the contents of a directory? It would then always process all files in that directory. You would not even use JavaScript in that case. I assume that you have Acrobat X (otherwise you would have used the term batch sequence instead of action). If that's not the case, let me know which version of Acrobat you are using.
0
 
LVL 14

Author Comment

by:EMB01
ID: 36502529
>>  I assume that you have Acrobat X

I am using Acrobat X.  

>>  have you looked into running your action on the contents of a directory?

Please explain :).
0
 
LVL 14

Author Comment

by:EMB01
ID: 36502705
Oh, I see what you mean...  Yes, I can run the action on a directory; however, that still requires me to start acrobat, doesn't it?  I want to not have to start acrobat at all.  Something like how this thing works (creates a batch file and runs from command line):

"AutoBatch™ is an advanced plug-in for Adobe® Acrobat Professional® software. AutoBatch™ adds a command-line batch file functionality to the Adobe® Acrobat Professional®. It allows users to execute any existing Acrobat batch sequence from a command-line prompt or a batch file."

Ref.  http://www.evermap.com/autobatch.asp#tag2
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36502807
As you can see from the link you've provided, something like that requires more than just Acrobat (in this case, I assume an Acrobat plug-in). With just Acrobat, that's not possible. Also, Adobe does not like it when you use Acrobat in a "server like" environment where potentially more than just one user can access and make use of Acrobat (see the EULA you've agreed to when you installed Acrobat for more details).
0
 
LVL 14

Author Comment

by:EMB01
ID: 36503148
SO, this has to be done via plugin?  Can plugins be written in javascript?  I can't find any api reference or resources on writing adobe plugins from adobe?  Do they provide such documentation, and if so, can someone please share it with me?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36503287
No, plugins need to be written in C/C++. You can find the Acrobat SDK at http://www.adobe.com/devnet/acrobat.html
Let me warn you however: Getting familiar with the Acrobat SDK is a long process, and it would be much cheaper and quicker to buy the product you linked to earlier (I don't know if it would work with Acrobat X, that's something you would have to find out).
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
This article discusses how to create an extensible mechanism for linked drop downs.
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now