summaryrefslogtreecommitdiff
path: root/pdf2png
diff options
context:
space:
mode:
authorJake VanderVaate <jake.vandervaate@protonmail.com>2022-02-28 23:00:00 -0600
committerJake VanderVaate <jake.vandervaate@protonmail.com>2022-02-28 23:00:00 -0600
commit72c64974b4a43d2e201a174e15853e92e0fe1d81 (patch)
tree7bb7c3cc58e73ddcf6c65dea6d15a63f247a0f24 /pdf2png
parentb8b5ee4dc499d3069bdef5e856c44e8cd8a6f476 (diff)
added pdf2png script
Diffstat (limited to 'pdf2png')
-rwxr-xr-xpdf2png31
1 files changed, 31 insertions, 0 deletions
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