1

The command

pdftk FileOne.pdf "File two.pdf" output Combined.pdf  

works as expected, merging PDF's One and Two. However, if I put the filenames in a file

FileOne.pdf 
"File Two.pdf"  

and then use

pdftk $(< Files.lst) output Combined.pdf  

I get the error messages

Error: Failed to open PDF file: 
   "File  
Error: Unable to find file.
Error: Failed to open PDF file: 
   Two.pdf"  

Obviously, pdftk is seeing the quotes, so I don't understand how it can distinguish the two cases (which is why I am posing the question in this forum).

For the record, I am using MKS Toolkit Korn shell, invoked from Emacs. I get the same in the Cygwin bash shell.

3 Answers 3

2

Write the file as:

FileOne.pdf 
File Two.pdf

And use as:

set -f
IFS='
' # split on newline only
pdftk $(< Files.lst) output Combined.pdf
0

You have two problems (at least).

The first is you need to read your source file (Files.list) one line at at time. You can probably do this more then one way, but one way is with read

See : https://stackoverflow.com/questions/10929453/bash-scripting-read-file-line-by-line

Second is due to the spaces in your file names (resulting in the error "Failed to open PDF file: Two.pdf" ). You need to either quote your variables or escape the space.

so any of the following works with spaces in the file name,

echo "$variable"
cat "File with spaces.txt" 
cat 'File 2.txt'
cat File\ 3\ with\ spaces.txt

There is an elegant solution here:

https://stackoverflow.com/questions/19122448/bash-escaping-spaces-in-filename-in-variable

0

You can remove the quotes from the text file, and read it into an array with bash's mapfile:

mapfile -t files < Files.lst
pdftk "${files[@]}" output Combined.pdf  
1
  • 1
    This would be a good answer if the question didn't specifically mention the use of a shell other than bash. Commented Dec 14, 2013 at 22:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .