function pdf_extract if test (count $argv) -lt 4 echo "Usage: pdf_extract " return 1 end set input_file $argv[1] set from_page $argv[2] set to_page $argv[3] set output_file $argv[4] if not test -f $input_file echo "Error: input file '$input_file' not found" return 1 end set tmp_prefix (string replace -r '\.pdf$' '' $input_file)_extract_tmp_ pdfseparate -f $from_page -l $to_page $input_file "$tmp_prefix%04d.pdf" && pdfunite $tmp_prefix*.pdf $output_file && rm $tmp_prefix*.pdf end