Skip to content

Instantly share code, notes, and snippets.

@mihaisoloi
Created June 1, 2012 21:36
Show Gist options
  • Save mihaisoloi/2855278 to your computer and use it in GitHub Desktop.
Save mihaisoloi/2855278 to your computer and use it in GitHub Desktop.
Script for parsing csv table of contents and aggregating a number of pdfs with bookmarks using pdftk and gs
#!/bin/bash
files=""
options=""
title=""
pages=0
page_number=1
i=1
for f in TCST\ *.pdf
do
pages=$(pdfinfo "$f" | grep Pages | awk '{print $2}')
#echo '~~~>>' + $pages
f=${f// /\\ }
title=$(awk "NR==${i}" 'ToC.csv')
#echo $i + '~~~~' + $title
((i++))
options="${options} -c [\"/Page ${page_number} /View [/XYZ null null null] /Title (${title}) /OUT pdfmark\""
page_number=$((${pages} + ${page_number}))
#echo $page_number
files="${files} ${f}"
done
#echo $files
#echo $options
echo "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=TCST.pdf $options -dBATCH $files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment