~hnaguski/combinepdf

script using ghostscript and pdftk to combine pdfs

~kota via inbox

7 months ago

145a864 update readme

11 months ago
combinepdf
==========

usage
-----

combinepdf PATH

about
-----

combinepdf is a close-to-POSIX shell script that combines pdfs, and adds an
index based on the file hierarchy. Kota and I wrote this to combine the pdfs in
a copy of my car's FSM which had each chapter in its own pdf for some reason.
Its file higherarchy looked something like the following, so you may notice
some quirks in the script.

manual
├── 0001. SECTION 1
│   ├── 0001. CHAPTER 1.pdf
│   ├── 0002. CHAPTER 2.pdf
│   ├── 0003. CHAPTER 3.pdf
│   └── 0004. SUBSECTION
│       ├── 0001. CHAPTER 1.pdf
│       ├── 0002. CHAPTER 2.pdf
│       ├── 0003. CHAPTER 3.pdf
├── 0002. SECTION 2
│   ├── 0001. SUBSECTION
│   │   ├── 0001. CHAPTER 1.pdf
│   │   ├── 0002. CHAPTER 2.pdf
│   │   ├── 0003. CHAPTER 3.pdf

Hopefully combinepdf isn't too difficult to modify in order to suit your own
needs. If you do anything neat with it, or have any ideas to improve it,
consider letting me know on my mailing list by sending a plain text email to
~hnaguski/inbox@lists.sr.ht

required tools
--------------

POSIX sh
ghostscript
pdftk
find, sort, xargs NUL character handling

non-POSIX bits
--------------

This line is used to combine the pdfs:

find "$1" -name "*.pdf" -print0 | sort -z | xargs -0 gs -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=tmp.pdf -dBATCH

It uses an extension in find, sort, and xargs to use the NUL character (\0) as
the delimiter, which makes passing the output to ghostscript easier. These
extensions seem to be avaliable in the GNU, various BSDs, and busybox versions
of the programs.

Other non-posix things include ghostscript and pdftk.