See if anyone can help me. For example:
I have a .pdf document with 4 pages.
With the command below I can make this .pdf document have two pages, that is, two pages on the same sheet in "landscape" format
cpdf -twoup-stack in.pdf -o out.pdf
But I need to make it work on multiple files in the same folder. I tried the command below and it didn't work. If anyone has a solution I would appreciate it, I'm a beginner.
This prints only one file from the folder.
cpdf -twoup-stack path\*.pdf -o out.pdf
Looks like your using the windows version thus from cmd prompt to process all multi-page files in current folder you could use the simpler
forfiles /m *.pdf /c "cmd /c cpdf -twoup-stack in.pdf -o out-@file"so in1.pdf becomes out-in1.pdf
similar is
for %f in (*.pdf) do cpdf -twoup-stack in.pdf -o "out-%f"It is more convenient to use a batch.cmd file with a different
forstructure, with some variables to allow drag and drop or specify a default folder etc.so if the following
2up.cmdis placed in a work folder with multiple pdfs it will on entering2upat a cmd prompt ora simple double clickon that cmd file then process all the pdf files in that working folder.Note a batch file needs %% where a cmd line would just need one but the single %~ inside the brackets is correct ! also define the folder for cpdf to ensure it is the only cpdf command accessed and generally "double quote" to avoid problems with spaces.
The result will be a rotated imposition compared to source pages so the next step is usually add a second command at the end to rotate those-out.PDFs.
for %%F in ("%~dp0*-out.pdf") do "c:\path to\cpdf.exe" -rotate 90 "%%F" -o "%%~dpnF-2up.pdf"If you are going to run twice for 4-up it becomes more desirable to delete work files so in that case consider if a 3rd)
del "%~dp0*-out.pdf"is also required before 4) ...*-2up.pdf ...-out.pdf and 5) -out.pdf to -4up.pdf4-up is generally 2-up twice so I gave hints above about add extra lines at the end, in comments you tried and found only 3 steps as for loops needed for your desired use :-
This may not be the most efficient way (but is now one single
forloop, so retains the logic) it can be used as a template for different executables and different function sequences.4-up.cmd
You can delete those
dirlines echoing progress, if you want a more silent run and then the pause is not required if double click running the cmd file.To save your -outputs in a different folder the simplest will be to change end of last
-o "%~dp0!name!-4up.pdf"to point to a different folder but keep the Filename so
-o "c:\folder name\!name!.pdf"To adapt to a remote folder or for drag and drop is beyond this question so try
FOR /?to see many other options including adapting to work with sub directories. For a single file drag and drop variant modify similar to https://github.com/GitHubRulesOK/MyNotes/blob/master/AppNotes/SumatraPDF/Addins/N-Up-PDF/2-Up-PDF.cmd