1#compdef pdftk
2
3_pdfwithhandle()
4{
5    compset -P '(#I)[A-Z]='
6    _files "$@" -g '(#i)*.pdf'
7}
8
9local expl
10local -a opts operations
11
12opts=(output encrypt_40bit encrypt_128bit allow owner_pw user_pw flatten
13	compress uncompress keep_first_id keep_final_id drop_xfa verbose
14	dont_ask do_ask)
15operations=(cat attach_files unpack_files burst fill_form background stamp
16	generate_fdf multibackground multistamp dump_data dump_data_fields
17	update_info)
18
19case $words[CURRENT-1] in
20    ((input|owner|user)_pw)
21	_message "password, or PROMPT"
22	;;
23
24    (allow)
25	#_description permissions expl "permission"
26	#compadd $expl \
27	_values -s , permissions \
28	    Printing DegradedPrinting ModifyContents Assembly CopyContents \
29	    ScreenReaders ModifyAnnotations FillIn AllFeatures
30	;;
31
32    (attach_files)
33	_files "$@"
34	;;
35
36    (fill_form)
37	_description files expl 'FDF and XFDF files'
38	_files "$@" $expl -g '(#i)*.(fdf|xfdf)'
39	;;
40
41    ((multibackground|background|stamp|multistamp|output))
42	_description files expl 'PDF files'
43	_files "$@" $expl -g '(#i)*.pdf'
44	;;
45
46    (update_info)
47	_files
48	;;
49
50    (*)
51	false
52	;;
53esac && return 0
54
55if [[ -n $words[(r)(${(j:|:)operations})] ]]; then
56    _description options expl "options"
57    compadd $@ $expl $opts
58else
59    _tags files operations
60    _alternative \
61	'files:PDF files:_pdfwithhandle' \
62	"operations:operations:($operations)"
63fi
64