Last active
June 22, 2023 16:42
-
-
Save axfelix/64e88f6c6725ec36bac7f3f3f6981146 to your computer and use it in GitHub Desktop.
dip-maker script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Requires enscript, ps2pdf, LibreOffice, pdftk | |
# brew install enscript ghostscript pdftk-java | |
# brew install --cask libreoffice | |
# Also, if you're on macOS, this needs gnu find | |
# brew install coreutils, then: | |
# export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH" | |
currentdir=$(pwd) | |
cd $1 | |
title=$(basename $(pwd)) | |
mkdir access | |
# list file names and modified date/times with sorting | |
find . -maxdepth 1 -type f -printf "%T+#%Tb %Td %TH:%TM\t%p\n" | sort -rn | cut -d# -f2- | head -8 > directory_listing.txt | |
# make pdf from output of previous command | |
# this is currently using a postscript pipeline, could also use pandoc or a2x | |
# see https://www.baeldung.com/linux/convert-text-to-pdf | |
enscript --header="$title" --word-wrap directory_listing.txt -p directory_listing.ps; | |
ps2pdf directory_listing.ps $title.pdf | |
rm directory_listing.txt | |
rm directory_listing.ps | |
# convert all docs to PDFs | |
for x in $(find $1 -not -type d) | |
do | |
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf $x --outdir access | |
done | |
# make each PDF contain a single bookmark to first page | |
cd access | |
tempPDF=`mktemp` | |
for i in *.pdf | |
do | |
bookmarkTitle=`basename "$i" .pdf` | |
bookmarkInfo="BookmarkBegin\nBookmarkTitle: $bookmarkTitle\nBookmarkLevel: 1\nBookmarkPageNumber: 1" | |
pdftk "$i" update_info_utf8 <(echo -en $bookmarkInfo) output $tempPDF verbose | |
mv $tempPDF "$i" | |
done | |
cd .. | |
# concatenate the PDFs | |
pdftk access/*.pdf cat output access/combined.pdf | |
# merge front page together with output PDF, clean up | |
pdftk $title.pdf access/combined.pdf cat output final.pdf | |
rm $title.pdf | |
rm access/*.pdf | |
mv final.pdf $title.pdf | |
cp $title.pdf access/$title.pdf | |
cd $currentdir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment