Dmitri
Dmitri

Reputation:

Opening multiple PDF documents using batch file

I am trying to open several PDF documents using a simple batch file:

ECHO OFF
CLS
cd Program Files\Adobe\Reader 9.0\Reader
Acrord32.exe C:\Users\BW1.pdf
Acrord32.exe C:\Users\BW2.pdf
Acrord32.exe C:\Users\BW3.pdf
Acrord32.exe C:\Users\BW4.pdf
Acrord32.exe C:\Users\BW5.pdf
Acrord32.exe C:\Users\BW6.pdf
EXIT

The above batch file opens the first PDF only, then waits until I close it for the next PDF file to open. How can I have all the PDF documents open at the same time? (Like going to Acrobat Reader, file->Open->xx.pdf)

Upvotes: 8

Views: 40479

Answers (7)

JSON C11
JSON C11

Reputation: 11792

For every pdf file in the specified directory, use the start command on that file:

for %f in ("C:\Users\*.pdf") do start %f

As per the Microsoft Docs:

For runs a specified command for each file in a set of files.

for {%variable|%%variable} in (set) do command [ CommandLineOptions]

Upvotes: 0

Dr.Ramachandra H.M
Dr.Ramachandra H.M

Reputation: 1

This is follow up to the answer given by JSON C11 above. I checked in Windows 10 OS, the command given as below with the error ("C:\Users*.pdf") was unexpected at this time. for %f ("C:\Users*.pdf") do start %f What is missing is 'in'. Correct code is...

    for %f in ("C:\Users\*.pdf") do start %f 

If you have a binary to open that particular type of file, and you like to open in maximized view, you can use the following code.

    for %f in ("C:\Users\*.pdf") do start /max <path to binary> %f

Upvotes: -1

Assaf Lavie
Assaf Lavie

Reputation: 75913

Use start:

start acrord32.exe 1.pdf
start acrord32.exe 2.pdf
start acrord32.exe 3.pdf

Or even (as Johannes Rössel suggests in the comment below):

start 1.pdf
start 2.pdf
start 3.pdf

Would probably work as well (depending on your default PDF viewer).

Note that when using start you have to be careful when using quoted arguments, as the following won't work (the first quoted argument is interpreted as the title for a new console window):

start "1.pdf"

Instead you'll have to do the following:

start "" "1.pdf"

It's an annoying quirk of start, but you have to effectively supply a dummy title in this case to properly open the specified file (even though the title is unnecessary as this won't create a new console window).

A list of other available batch commands.

Upvotes: 15

Feroz
Feroz

Reputation: 1

Thanks for the above answers.

I also tried below, working fine:

start /B excel.exe "D:\my first file.xlsx" "E:\my second file.xlsx" "D:\working folder\my third file.xlsx"

Upvotes: 0

Kurt Pfeifle
Kurt Pfeifle

Reputation: 90193

For me it works even without the start command. I use:

c:\path\to\my.pdf

in cmd.exe windows frequently, and it always opens Acrobat Reader (my default viewer on Windows). In a batchfile I've written to generate PDF via Ghostscript, my last two lines are:

"%ouptutpath%\%outputfile%.pdf"
"%outputpath%\%outputfile%-optimized.pdf"

which automatically opens both generated PDFs in two different Reader windows. (My %outputpath% contains spaces, the %outputfile% may also have some...)

Upvotes: 2

Dmitri
Dmitri

Reputation:

Thank you!

Using start did the trick. I had to use start as many times as the number of pdf documents I want to open. For some reason

start acrord32.exe 1.pdf 2.pdf 3.pdf

opens only the first document. So I guess Acrobat reader might not allow for more files on the command line.

I rally appreciate your answers.

Upvotes: 0

user83286
user83286

Reputation:

Have you tried whether Acrobat Reader allows for more files on the commandline, ie.

start acrord32.exe 1.pdf 2.pdf 3.pdf

Upvotes: 0

Related Questions