Skip to content

Instantly share code, notes, and snippets.

@pniedzwiedzinski
Created August 12, 2020 14:44
Show Gist options
  • Save pniedzwiedzinski/d892fa4ad882468f32d87178718436bd to your computer and use it in GitHub Desktop.
Save pniedzwiedzinski/d892fa4ad882468f32d87178718436bd to your computer and use it in GitHub Desktop.
Download websites as pdfs
#!/usr/bin/env nix-shell
#! nix-shell -p chromium pdftk -i sh
## Download webpages into pdfs
##
## Usage
## -----
##
## Put list of links into /tmp/urls and run script.
[ -f /tmp/result ] || mkdir -p /tmp/result
for url in `cat /tmp/urls`; do
name=`echo $url | sed 's/.*\/\(.*\)\/$/\1/'`
chromium --headless --print-to-pdf=/tmp/$name.pdf $url > /dev/null
# OPTIONAL: Remove first and last page (header, footer)
pdftk /tmp/$name.pdf cat 2-r2 output /tmp/result/$name.pdf > /dev/null
echo "Saved to /tmp/result"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment