pdfpages

count the pages of a PDF
git clone https://riazj.com/git/pdfpages
Log | Files | Refs | README | LICENSE

commit 0964738ea0eeb1744f4fb08febb08ac37e3b61bd
parent 4867cc4395b38053640de3795d39496b90aa273c
Author: Riaz <riaz@riazj.com>
Date:   Sat,  4 Oct 2025 14:12:41 -0700

Improve speed of script example

Diffstat:
MREADME | 26+++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/README b/README @@ -5,24 +5,20 @@ I use to get a list of PDFs with their page count. #!/bin/sh -e + list="page-count.txt" cd "$HOME/data/books" + for f in *.pdf; do - pdfpages "$f" >> page-count.txt.tmp + if [ ! -s "$list" ] || ! grep "$f" "$list" >> "$list.tmp"; then + pdfpages "$f" >> "$list.tmp" + fi done - sort -V page-count.txt.tmp > page-count.txt - rm page-count.txt.tmp - -The difference is only a few tenths of a second when using pdfinfo instead of this program. - - #!/bin/sh -e + sort -V "$list.tmp" > "$list" + rm "$list.tmp" - cd "$HOME/data/books" - for f in *.pdf; do - pages="$(pdfinfo "$f" | grep Pages)" - pages="${pages##* }" - echo "$pages: $f" >> page-count.txt.tmp - done +To use pdfinfo instead, replace pdfpages with the following: - sort -V page-count.txt.tmp > page-count.txt - rm page-count.txt.tmp + pages="$(pdfinfo "$f" | grep Pages)" + pages="${pages##* }" + echo "$pages: $f" >> "$list.tmp"