Created
October 18, 2022 08:30
-
-
Save olberger/a88e3e2d4c684fdf94bbe5bc69ab9fe2 to your computer and use it in GitHub Desktop.
convert wrapper to use pdftoppm in pdfsandwich
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Convert wrapper for pdfsandwich, to avoid using imagemagick's convert for PDF to PBM conversion, as it relies on GS under the hood, | |
# and GS security settings disallow such conversion on most distros. | |
# Instead of ImageMagick's convert, we then rely on poppler-utils' pdftoppm | |
# To be invoked with 'pdfsandwich -convert .../convert.sh' | |
# By using this I figured out the options passed | |
# convert -verbose $* | |
# which are of the form | |
# -units PixelsPerInch -type Bilevel -density 300x300 -verbose "/tmp/pdfsandwich_tmp743704/pdfsandwich_inputfile86bb3e.pdf[1]" /tmp/pdfsandwich_tmp743704/pdfsandwichcdbaf6.pbm | |
# Extract first "file + page" arg | |
pdffile="${@: -2:1}" | |
# Calculate the page | |
page=$(echo $pdffile | sed -e 's/[^\[]*\[//' -e 's/\]//') | |
page=$(expr $page + 1) | |
# cleanup the PDF filename | |
pdffile=$(echo $pdffile | sed -e 's/\[.*//') | |
# The script is invoked twice : for PDF to PBM conversion and later. Only the first one is diverted | |
if [ "${pdffile: -4}" == ".pdf" ]; then | |
pdftoppm -singlefile -f $page -l $page "$pdffile" "${@: -1}" | |
mv "${@: -1}".ppm "${@: -1}" | |
else | |
convert $* | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment