Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share

3 Answers 3

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
share

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 : http://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:

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

share

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  
share
    
This would be a good answer if the question didn't specifically mention the use of a shell other than bash. –  Gilles Dec 14 '13 at 22:34

This site is currently not accepting new answers.

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