Files
dotfiles/fish/functions/pdf_extract.fish
T

23 lines
616 B
Fish

function pdf_extract
if test (count $argv) -lt 4
echo "Usage: pdf_extract <input_file> <from_page> <to_page> <output_file>"
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