Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/scripts/pdftohtml.sh @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 #!/bin/bash | |
| 2 # | |
| 3 # Convert PDF to hybrid HTML output with images and line art rendered to a | |
| 4 # background image, and text overlaid on top as absolutely positioned HTML | |
| 5 # text. | |
| 6 | |
| 7 input=$1 | |
| 8 out=${2:-out} | |
| 9 fmt=${3:-png} | |
| 10 dpi=${4:-96} | |
| 11 | |
| 12 scale=$(expr 72 '*' $dpi / 96) | |
| 13 | |
| 14 if test -f "$1" | |
| 15 then | |
| 16 echo Processing "$input" out=$out fmt=$fmt dpi=$dpi | |
| 17 else | |
| 18 echo "usage: pdftohtml.sh input.pdf output-stem image-format dpi" | |
| 19 echo " example: pdftohtml.sh input.pdf output png 96" | |
| 20 exit | |
| 21 fi | |
| 22 | |
| 23 title=$(basename "$input" | sed 's/.pdf$//') | |
| 24 | |
| 25 mutool convert -Oresolution=$dpi -o $out.html "$input" | |
| 26 | |
| 27 sed -i -e "/<head>/a<title>$title</title>" $out.html | |
| 28 sed -i -e "/^<div/s/page\([0-9]*\)\" style=\"/page\1\" style=\"background-image:url('$out\1.$fmt');/" $out.html | |
| 29 | |
| 30 mutool draw -K -r$dpi -o$out%d.png "$input" | |
| 31 | |
| 32 echo Converting to $fmt | |
| 33 for png in $out*.png | |
| 34 do | |
| 35 xxx=$(basename $png .png).$fmt | |
| 36 case $fmt in | |
| 37 png) | |
| 38 if command -v optipng >/dev/null | |
| 39 then | |
| 40 optipng -silent -strip all $png | |
| 41 fi | |
| 42 ;; | |
| 43 jpg) | |
| 44 if command -v mozjpeg >/dev/null | |
| 45 then | |
| 46 mozjpeg -outfile $xxx $png | |
| 47 else | |
| 48 convert -format $fmt $png $xxx | |
| 49 fi | |
| 50 ;; | |
| 51 webp) | |
| 52 if command -v cwebp >/dev/null | |
| 53 then | |
| 54 cwebp -quiet -o $xxx $png | |
| 55 else | |
| 56 convert -format $fmt $png $xxx | |
| 57 fi | |
| 58 ;; | |
| 59 *) | |
| 60 convert -format $fmt $png $xxx | |
| 61 ;; | |
| 62 esac | |
| 63 done |
