#!/bin/bash # # Script to rasterize a PDF file # # You can adjust the density ("convert" argument) # or other options as you wish # # It is a function so that you can include in your .bashrc (or whatever) # and use as a command # # # Based on: https://superuser.com/a/1588781 # rasterizePdf() {( set -e if [ $# -eq 0 ]; then echo "Rasterize a PDF" >&2 echo "Usage: $0 " >&2 exit 1 fi for input in "$@"; do tmp="$(mktemp).pdf" output="${input%.*}-raster.pdf" convert \ -render \ -density 300 \ "$input" \ "$tmp" gs \ -sDEVICE=pdfwrite \ -dCompatibilityLevel=1.4 \ -dNOPAUSE \ -dQUIET \ -dBATCH \ -sOutputFile="$output" \ "$tmp" rm -f "$tmp" "${tmp%.*}" echo -e "✅ $input \033[2m\n to $output\033[0m" done )} # rasterizePdf YOUR_FILE.pdf