#!/bin/bash # # Convert PDF to hybrid HTML output with images and line art rendered to a # background image, and text overlaid on top as absolutely positioned HTML # text. input=$1 out=${2:-out} fmt=${3:-png} dpi=${4:-96} scale=$(expr 72 '*' $dpi / 96) if test -f "$1" then echo Processing "$input" out=$out fmt=$fmt dpi=$dpi else echo "usage: pdftohtml.sh input.pdf output-stem image-format dpi" echo " example: pdftohtml.sh input.pdf output png 96" exit fi title=$(basename "$input" | sed 's/.pdf$//') mutool convert -Oresolution=$dpi -o $out.html "$input" sed -i -e "//a$title" $out.html sed -i -e "/^
/dev/null then optipng -silent -strip all $png fi ;; jpg) if command -v mozjpeg >/dev/null then mozjpeg -outfile $xxx $png else convert -format $fmt $png $xxx fi ;; webp) if command -v cwebp >/dev/null then cwebp -quiet -o $xxx $png else convert -format $fmt $png $xxx fi ;; *) convert -format $fmt $png $xxx ;; esac done