3
2
I am trying to create a batch OR .bat file that will linearize MULTIPLE PDF files. I already have a script I commandeered that uses PDFTK that sends PDFs to the 'sendto' folder where they are combined. I would like to do the same with qpdf but use the --linearize
command instead.
The main problem is, I cannot combine the files first into one PDF using PDFTK and then linearize the one file - the files still turn out too big. What works the best is if I linearize each INDIVIDUAL file, and then combine them. It would probably be best if I could also combine them using qpdf, that way I wouldn't have to use two different programs.
IN SUMMATION:
This is the current bat file I have that works perfectly (below) -> I can select multiple PDF files, drop them into the bat file and out pops a new PDF file named Combined_PDFs.pdf. I want to do the SAME with qpdf, except linearize, THEN combine the files. I cannot get the syntax right, I simply do not know enough about bat files.
CURRENT WORKING SCRIPT:
@echo off
PUSHD "%~dp0"
setlocal enabledelayedexpansion
FOR %%A IN (%*) DO (set command=!command! %%A)
pdftk.exe %command% cat output "%~dp1Combined_PDFs.pdf" compress
This script works, but it will ONLY work for one file at a time:
@echo off
PUSHD "%~dp0"
setlocal enabledelayedexpansion
FOR %%A IN (%*) DO (set command=!command! %%A)
qpdf.exe --linearize %command% "%~dpn1_Reduced%~x1"
I need the script above to work for multiple inputs.
Hmm, this seems to work good for one file. However, when I select more than one file it looks like it processes all the files correctly but names them all the same name (first file selected_Reduced.pdf). This of course will write over the previous files, leaving only one file produced. – matt m – 2014-05-22T17:05:39.933
My apologies! I've updated the FOR loop. Previously it was coded to only use the first filename. Now it should use the name of the file currently being processed in addition to the extension of the file being processed (in case they are different).
The difference is the double percent sign, and the use of the variable "A". – Kevin Bennett – 2014-05-23T03:39:37.807
Works like a charm! Thank you so very much! I hate to push my luck...but is there anyway I could batch combine the _Reduced files from there (either with PDFtk or qpdf)? – matt m – 2014-05-23T15:54:15.680
If I understand what you are asking, it seems like you could use the batch file I showed in the answer, and then add the portion of your first batch file that combines all of the Reduced PDF files. So at the end of the batch file add:
FOR %%A IN (%*) DO (set command=!command! "%%~dpnA_Reduced%%~xA") pdftk.exe %command% cat output "%~dp0Combined_PDFs.pdf" compress
This should put all of the Reduced files into the variable "command", and then pass that to the pdftk.exe application. Note that, in this example, the final file will end up in the directory where the batch file is located. – Kevin Bennett – 2014-05-23T21:35:12.150