Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert a directory of images into a single PDF
    primarykey
    data
    text
    <p>I have a directory of images:</p> <pre><code>path/to/directory/ image01.jpg image02.jpg ... </code></pre> <p>and would like to convert it into a single PDF file:</p> <pre><code>path/to/directory.pdf </code></pre> <p>This is what I managed to code so far:</p> <pre><code>#!/bin/bash echo Directory $1 out=$(echo $1 | sed 's|/$|.pdf|') echo Output $out mkdir tmp for i in $(ls $1) do # MAC hates sed with "I" (ignore case) - thanks SO for the perl solution! # I want to match "jpg, JPG, Jpg, ..." echo $1$i $(echo "tmp/$i" | perl -C -e 'use utf8;' -pe 's/jpg$/pdf/i') convert $1$i $(echo "tmp/$i" | perl -C -e 'use utf8;' -pe 's/jpg$/pdf/i') done pdftk tmp/*.pdf cat output $out rm -rf tmp </code></pre> <p>So the idea was to convert each image into a pdf file with imagemagick, and use pdftk to merge it into a single file. Thanks to the naming of the files I don't have to bother about the ordering.</p> <p>Since I'm a newbie to this I'm sure there are many refinements one can do:</p> <ul> <li>only iterate over image-files in the directory (in case there is some Readme.txt,...)</li> <li>including the extensions png, jpeg, ...</li> <li>using the trailing "/" is not elegant I admint</li> <li>etc.</li> </ul> <p>Currently my main problem is, however, that there are cases where my directories and image files contain spaces in their names. The for-loop then iterates over sub-strings of the filename and I imagine that the line with convert will also fail. I have tried out some things but haven't succeeded so far and hope someone will be able to help me here. If anyone has ideas to address the issues I listed above as well I would be very glad to hear them too. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload