# Usage
#
#   pdf2jpg in.pdf  # => in.jpg
#
#   pdf2jpg in.pdf out.jpg  # => out.jpg
#
function pdf2jpg --description "Convert a (scanned) PDF to a JPG"

  function _print_usage
    echo -e "Usage:\n  pdf2jpg in.pdf\n  pdf2jpg in.pdf out.jpg"
  end

  switch (count $argv)
    case 0  # No arguments, error.
      _print_usage
      return 1

    case 1  # One argument.
      switch $argv
        case '-h' '--h' '--he' '--hel' '--help'
          _print_usage
          return 0

        case '-*'
          printf "%s: Unknown option %s\n" pdf2jpg $argv
          return 1

        case '*.pdf' '*.PDF'
          set pdf $argv[1]

        case '*'
          _print_usage
          return 1
      end

    case 2  # Two arguments.
      switch (echo $argv)
        case '*.pdf *.jpg' '*.pdf *.jpeg' '*.PDF *.jpg' '*.PDF *.jpeg'
          set pdf $argv[1]
          set jpg $argv[2]

        case '*'
          _print_usage
          return 1
      end

    case \*  # Too many arguments, error.
      printf "%s: Expected one or two arguments, got %d\n" pdf2jpg (count $argv)
      return 1
  end

  if set --query jpg  # Use the given output filename.
    convert -quiet -density 150 -trim $pdf -quality 100 -sharpen 0x1.0 $jpg
  else  # Use the filename of the PDF.
    set jpg (filename $pdf).jpg
    convert -quiet -density 150 -trim $pdf -quality 100 -sharpen 0x1.0 $jpg
  end
end


Add fish function for converting PDFs to JPGs.
Add fish function for converting PDFs to JPGs.

If I need to scan a document, I use Google Drive's scan feature on my
phone which creates a PDF. But sometimes you need an image.
This converts the scanned PDF to a sharp and readable JPG.

Although the size of the JPG isn't that large (relative to the PDF),
it may be worth adding a compression option to reduce the size.
Something to consider...

dideler/dotfiles,dideler/dotfiles