Skip to main content

Here is a small script (stackprinter) which uses Stack Printer from the command-line:

#!/bin/sh
type wkhtmltopdf || { echo >&2 "wkhtmltopdf command is required. Aborting."; exit 1; }
: ${1?"Usage: $0 (url)"}
URL=$1 && shift
HOST=$(echo $URL"$URL" | egrepgrep -oEo "([.[:alnum:]]*?)\.(com|net|org)" | head -c-5)
QID=$(echo $URL"$URL" | grep -o "\d"[0-9].*/" | head -c-2)
PRINTURL="http://www.stackprinter.com/export?format=HTML&printer=true&service=$HOST&question=$QID"
FILENAME=$(curl -s $URL"$URL" | grep -o "<title>[^<]*" | tail -c+8)
wkhtmltopdf $* $PRINTURL"$PRINTURL" "$FILENAME.pdf" && echo "'$FILENAME.pdf' saved."

Usage:

./stackprinter (url)

Example (tested on OS X):

$ ./stackprinter http://stackapps.com/questions/179/stackprinter-the-stack-exchange-printer-suite
'app - StackPrinter: The Stack Exchange Printer Suite - Stack Apps.pdf' saved.

Here is a small script (stackprinter) which uses Stack Printer from the command-line:

#!/bin/sh
type wkhtmltopdf || { echo >&2 "wkhtmltopdf command is required. Aborting."; exit 1; }
: ${1?"Usage: $0 (url)"}
URL=$1 && shift
HOST=$(echo $URL | egrep -o "([.[:alnum:]]*?)\.(com|net|org)" | head -c-5)
QID=$(echo $URL | grep -o "\d.*/" | head -c-2)
PRINTURL="http://www.stackprinter.com/export?format=HTML&printer=true&service=$HOST&question=$QID"
FILENAME=$(curl -s $URL | grep -o "<title>[^<]*" | tail -c+8)
wkhtmltopdf $* $PRINTURL "$FILENAME.pdf" && echo "'$FILENAME.pdf' saved."

Usage:

./stackprinter (url)

Example (tested on OS X):

$ ./stackprinter http://stackapps.com/questions/179/stackprinter-the-stack-exchange-printer-suite
'app - StackPrinter: The Stack Exchange Printer Suite - Stack Apps.pdf' saved.

Here is a small script (stackprinter) which uses Stack Printer from the command-line:

#!/bin/sh
type wkhtmltopdf || { echo >&2 "wkhtmltopdf command is required. Aborting."; exit 1; }
: ${1?"Usage: $0 (url)"}
URL=$1 && shift
HOST=$(echo "$URL" | grep -Eo "([.[:alnum:]]*?)\.(com|net|org)" | head -c-5)
QID=$(echo "$URL" | grep -o "[0-9].*/" | head -c-2)
PRINTURL="http://www.stackprinter.com/export?format=HTML&printer=true&service=$HOST&question=$QID"
FILENAME=$(curl -s "$URL" | grep -o "<title>[^<]*" | tail -c+8)
wkhtmltopdf $* "$PRINTURL" "$FILENAME.pdf" && echo "'$FILENAME.pdf' saved."

Usage:

./stackprinter (url)

Example (tested on OS X):

$ ./stackprinter http://stackapps.com/questions/179/stackprinter-the-stack-exchange-printer-suite
'app - StackPrinter: The Stack Exchange Printer Suite - Stack Apps.pdf' saved.
Added `printer=true` as suggested to avoid ads.
Source Link
kenorb
  • 173
  • 1
  • 6

Here is a small script (stackprinter) which uses Stack Printer from the command-line:

#!/bin/sh
type wkhtmltopdf || { echo >&2 "wkhtmltopdf command is required. Aborting."; exit 1; }
: ${1?"Usage: $0 (url)"}
URL=$1 && shift
HOST=$(echo $URL | egrep -o "([.[:alnum:]]*?)\.(com|net|org)" | head -c-5)
QID=$(echo $URL | grep -o "\d.*/" | head -c-2)
PRINTURL="http://www.stackprinter.com/export?format=HTML&service=$HOST&question=$QID"format=HTML&printer=true&service=$HOST&question=$QID"
FILENAME=$(curl -s $URL | grep -o "<title>[^<]*" | tail -c+8)
wkhtmltopdf $* $PRINTURL "$FILENAME.pdf" && echo "'$FILENAME.pdf' saved."

Usage:

./stackprinter (url)

Example (tested on OS X):

$ ./stackprinter http://stackapps.com/questions/179/stackprinter-the-stack-exchange-printer-suite
'app - StackPrinter: The Stack Exchange Printer Suite - Stack Apps.pdf' saved.

Here is a small script (stackprinter) which uses Stack Printer from the command-line:

#!/bin/sh
type wkhtmltopdf || { echo >&2 "wkhtmltopdf command is required. Aborting."; exit 1; }
: ${1?"Usage: $0 (url)"}
URL=$1 && shift
HOST=$(echo $URL | egrep -o "([.[:alnum:]]*?)\.(com|net|org)" | head -c-5)
QID=$(echo $URL | grep -o "\d.*/" | head -c-2)
PRINTURL="http://www.stackprinter.com/export?format=HTML&service=$HOST&question=$QID"
FILENAME=$(curl -s $URL | grep -o "<title>[^<]*" | tail -c+8)
wkhtmltopdf $* $PRINTURL "$FILENAME.pdf" && echo "'$FILENAME.pdf' saved."

Usage:

./stackprinter (url)

Example (tested on OS X):

$ ./stackprinter http://stackapps.com/questions/179/stackprinter-the-stack-exchange-printer-suite
'app - StackPrinter: The Stack Exchange Printer Suite - Stack Apps.pdf' saved.

Here is a small script (stackprinter) which uses Stack Printer from the command-line:

#!/bin/sh
type wkhtmltopdf || { echo >&2 "wkhtmltopdf command is required. Aborting."; exit 1; }
: ${1?"Usage: $0 (url)"}
URL=$1 && shift
HOST=$(echo $URL | egrep -o "([.[:alnum:]]*?)\.(com|net|org)" | head -c-5)
QID=$(echo $URL | grep -o "\d.*/" | head -c-2)
PRINTURL="http://www.stackprinter.com/export?format=HTML&printer=true&service=$HOST&question=$QID"
FILENAME=$(curl -s $URL | grep -o "<title>[^<]*" | tail -c+8)
wkhtmltopdf $* $PRINTURL "$FILENAME.pdf" && echo "'$FILENAME.pdf' saved."

Usage:

./stackprinter (url)

Example (tested on OS X):

$ ./stackprinter http://stackapps.com/questions/179/stackprinter-the-stack-exchange-printer-suite
'app - StackPrinter: The Stack Exchange Printer Suite - Stack Apps.pdf' saved.
Source Link
kenorb
  • 173
  • 1
  • 6

Here is a small script (stackprinter) which uses Stack Printer from the command-line:

#!/bin/sh
type wkhtmltopdf || { echo >&2 "wkhtmltopdf command is required. Aborting."; exit 1; }
: ${1?"Usage: $0 (url)"}
URL=$1 && shift
HOST=$(echo $URL | egrep -o "([.[:alnum:]]*?)\.(com|net|org)" | head -c-5)
QID=$(echo $URL | grep -o "\d.*/" | head -c-2)
PRINTURL="http://www.stackprinter.com/export?format=HTML&service=$HOST&question=$QID"
FILENAME=$(curl -s $URL | grep -o "<title>[^<]*" | tail -c+8)
wkhtmltopdf $* $PRINTURL "$FILENAME.pdf" && echo "'$FILENAME.pdf' saved."

Usage:

./stackprinter (url)

Example (tested on OS X):

$ ./stackprinter http://stackapps.com/questions/179/stackprinter-the-stack-exchange-printer-suite
'app - StackPrinter: The Stack Exchange Printer Suite - Stack Apps.pdf' saved.