From 66cdb395aa72d0dcd27979321c284750342a29b5 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 25 Dec 2019 11:08:25 +0100 Subject: [PATCH] [qutebrowser] add printing to pdf Use command page-to-pdf or shortcut gp to print current page to pdf and save it to default download directory. Fixes #66 --- .config/qutebrowser/config.py | 5 +++++ .local/share/qutebrowser/userscripts/pagetopdf.sh | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100755 .local/share/qutebrowser/userscripts/pagetopdf.sh diff --git a/.config/qutebrowser/config.py b/.config/qutebrowser/config.py index ce22e40..c63ab1f 100644 --- a/.config/qutebrowser/config.py +++ b/.config/qutebrowser/config.py @@ -125,6 +125,11 @@ config.bind(leader + 'bs', 'add-shaarli', mode='normal') c.aliases["archive-open"] = "open https://web.archive.org/web/{url}" config.bind(leader + 'ba', 'archive-open', mode='normal') +# save current page to pdf file +c.aliases["printpdf"] = "spawn --userscript pagetopdf.sh" +# set to gp, to mirror gd (download) just as go-Pdfdownload +config.bind('gp', 'printpdf', mode='normal') + # set stylesheets for the browser to use # leader - ss to remove all applied stylesheets config.bind(leader + 'ss', 'set content.user_stylesheets ""') diff --git a/.local/share/qutebrowser/userscripts/pagetopdf.sh b/.local/share/qutebrowser/userscripts/pagetopdf.sh new file mode 100755 index 0000000..143b030 --- /dev/null +++ b/.local/share/qutebrowser/userscripts/pagetopdf.sh @@ -0,0 +1,10 @@ +#! /usr/bin/bash +# Download current page as pdf file + +# use title of current page / selected text as filename +filename=${QUTE_SELECTED_TEXT:-$QUTE_TITLE} +# revert to default name if nothing else is set; remove special chars +filename=$(echo ${filename:-downloaded.pdf} | sed 's/[<>,/]/_/g') + +# print to pdf +echo "print --pdf '$QUTE_DOWNLOAD_DIR/${1:-$filename}.pdf'" >>"$QUTE_FIFO"