From 72c64974b4a43d2e201a174e15853e92e0fe1d81 Mon Sep 17 00:00:00 2001 From: Jake VanderVaate Date: Mon, 28 Feb 2022 23:00:00 -0600 Subject: added pdf2png script --- README.adoc | 32 ++++++++++++++++++++++++++++++++ pdf2png | 31 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 pdf2png diff --git a/README.adoc b/README.adoc index f44e197..4346774 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,5 @@ = My shell scripts +:toc: These are the shell scripts I've written for a broad range of tasks. Move these into your $PATH to call them without needing to provide a full path to the script to run it. @@ -11,6 +12,37 @@ This script monitors battery levels for 2 battery systems and sends notification At 5% the script notifies the user that the computer will lock in 60 seconds if not plugged in. If the computer isn't plugged in within 60 seconds, the screen locks with the command defined in the `lock_command` variable on line 3. +pdf2png:: +This script converts PDF pages to compressed PNG images. +It is useful for sending to cell phones or other situations where a PDF might be cumbersome. +The script also adds a 2 pixel, black border to the PNGs, which can be helpful for displaying them on white backgrounds. + +This script accepts up to 3 arguments: + +. The PDF to convert to PNG +. The first page to convert +. The last page to convert + +The full command can be + +`pdf2png example.pdf 1 5` + +If argument 3 is empty, the script only converts the page given in argument 2. + +`pdf2png example.pdf 1` + +If only the pdf name is given, the script only creates a PNG of the first page. + +`pdf2png example.pdf` + + +*Dependencies* + +* pdftoppm +* imagemagick +* optipng + + == Status bar scripts (sb-*) These status bar scripts use the https://fontawesome.com/v5/search?m=free[free FontAwesome Icons]. diff --git a/pdf2png b/pdf2png new file mode 100755 index 0000000..ae56a40 --- /dev/null +++ b/pdf2png @@ -0,0 +1,31 @@ +#!/bin/sh + +input_pdf="$1" +first_page="$2" +last_page="$3" +file_name="$(basename -s .pdf """$1""")" + +if [ "$2" = "" ] +then + first_page="1" +else + : +fi + +if [ "$3" = "" ] +then + last_page="$first_page" +else + : +fi + +#convert the PDF to a 600px wide PNG image +pdftoppm -f "$first_page" -l "$last_page" -png -scale-to-x 696 -scale-to-y -1 "$input_pdf" "$file_name" + +#add a 2x2px border to the image.png file +for file in "$file_name"*.png; do + convert "$file" -bordercolor black -border 2x2 "$file" + + #compress the image + optipng "$file"; +done -- cgit v1.2.1