#compdef qpdf

_qpdf_topics() {
  # qpdf --help | sed -e '1,/Topics/d' -e '/For/d' -e 's/:.*//g'
  local -a topics=(${(@f)"$(qpdf --help | sed -e '1,/Topics/d' -e '/For/d' | awk '/ [a-z]+/ { print $1 }' | sed -E 's/[:]//g')"})
  _values 'topics' $topics
}

_qpdf() {
  _arguments \
    '*:file:_files' \
    '--empty[Use in place of infile for an empty input. Especially useful with --pages]' \
    '--replace-input[Use in place of outfile to overwrite the input file with the output]' \
    '--job-json-file' \
    '--warning-exit-0[Use exit status 0 instead of 3 when warnings are present]' \
    '--completion-bash[Output a command that enables bash completion]' \
    '--completion-zsh[Output a command that enables zsh completion HELP (information about qpdf)]' \
    '--help=[Run help]:help:_qpdf_topics' \
    '--option' \
    '--version[Display the version of qpdf]' \
    '--copyright[Display copyright and license information]' \
    '--show-crypto[Show a list of available crypto providers, one per line]' \
    '--job-json-help[Describe the format of the QPDFJob JSON input used by]' \
    '--zopfli[If zopfli support is compiled in, indicate whether it is active]' \
    '--password' \
    '--password-file' \
    '--verbose[Output additional information about various things qpdf is doing]' \
    '--progress[Indicate progress when writing files]' \
    '--no-warn[Suppress printing of warning messages]' \
    '--deterministic-id[Generate a secure, random document ID only using static information]' \
    '--allow-weak-crypto[Allow creation of files with weak cryptographic algorithms]' \
    '--keep-files-open' \
    '--keep-files-open-threshold' \
    '--password-is-hex-key[Provide the underlying file encryption key as a hex-encoded string]' \
    '--suppress-password-recovery[Suppress qpdf'\''s usual behavior of attempting different encodings]' \
    '--password-mode' \
    '--suppress-recovery[Avoid attempting to recover when errors are found in a file'\''s cross reference]' \
    '--ignore-xref-streams[Ignore any cross-reference streams in the file, falling back to cross-reference]' \
    '--linearize[Create linearized (web-optimized) output files]' \
    '--encrypt' \
    '--decrypt[Create an unencrypted output file even if the input file was encrypted]' \
    '--remove-restrictions[Remove restrictions associated with digitally signed PDF files]' \
    '--copy-encryption' \
    '--encryption-file-password' \
    '--qdf[Create a PDF file suitable for viewing in a text editor and even editing]' \
    '--no-original-object-ids[Omit comments in a QDF file indicating the object ID an object had in original]' \
    '--compress-streams' \
    '--decode-level' \
    '--json-output[\[bu\] generalized: uncompress streams]' \
    '--stream-data' \
    '--recompress-flate[The default generalized compression scheme used by PDF is flate]' \
    '--compression-level' \
    '--jpeg-quality' \
    '--normalize-content' \
    '--object-streams' \
    '--preserve-unreferenced[Preserve all objects from the input even if not referenced]' \
    '--remove-unreferenced-resources' \
    '--preserve-unreferenced-resources[Synonym for --remove-unreferenced-resources=no. Use that instead]' \
    '--newline-before-endstream[For an extra newline before endstream]' \
    '--coalesce-contents[Concatenate array of content streams into a single content stream]' \
    '--externalize-inline-images[Convert inline images to regular images]' \
    '--ii-min-bytes' \
    '--min-version' \
    '--force-version' \
    '--pages' \
    '--file' \
    '--range' \
    '--collate' \
    '--split-pages' \
    '--overlay' \
    '--underlay' \
    '--flatten-rotation[For each page that is rotated using the /Rotate key in the page'\''s dictionary]' \
    '--flatten-annotations' \
    '--rotate' \
    '--generate-appearances[PDF form fields consist of values and appearances, which may be inconsistent]' \
    '--optimize-images[Attempt to use DCT (JPEG) compression for images that fall within certain content]' \
    '--oi-min-width' \
    '--oi-min-height' \
    '--oi-min-area' \
    '--keep-inline-images[Prevent inline images from being considered by --optimize-images]' \
    '--remove-info[Exclude file information (except modification date) from the output file]' \
    '--remove-metadata[Exclude metadata from the output file]' \
    '--remove-page-labels[Exclude page labels (explicit page numbers) from the output file]' \
    '--remove-structure[Exclude the structure tree from the output file]' \
    '--set-page-labels' \
    '--user-password' \
    '--owner-password' \
    '--bits' \
    '--accessibility' \
    '--annotate' \
    '--assemble' \
    '--extract' \
    '--form' \
    '--modify-other' \
    '--modify' \
    '--print' \
    '--cleartext-metadata[If specified, don'\''t encrypt document metadata even when encrypting the rest]' \
    '--use-aes' \
    '--allow-insecure[Allow creation of PDF files with empty owner passwords and non-empty user]' \
    '--force-V4[This option is for testing and is never needed in practice]' \
    '--force-R5[Use an undocumented, unsupported, deprecated encryption algorithm]' \
    '--to' \
    '--from' \
    '--repeat' \
    {--list-attachments,--show-attachment}'' \
    '--add-attachment' \
    '--copy-attachments-from' \
    '--remove-attachment' \
    '--key' \
    '--filename' \
    '--creationdate' \
    '--moddate' \
    '--mimetype' \
    '--description' \
    '--replace[Indicate that any existing attachment with the same key should be replaced]' \
    '--prefix' \
    '--is-encrypted[Silently exit with a code indicating the file'\''s encryption status:]' \
    '--requires-password[Silently exit with a code indicating the file'\''s password status:]' \
    '--check[Check the structure of the PDF file]' \
    '--show-encryption[Show document encryption parameters]' \
    '--show-encryption-key[When used with --show-encryption or --check, causes the underlying encryption]' \
    '--check-linearization[Check to see whether a file is linearized]' \
    '--show-linearization[Check and display all data in the linearization hint tables]' \
    '--show-xref[Show the contents of the cross-reference table or stream (object locations]' \
    '--show-object' \
    '--raw-stream-data[When used with --show-object, if the object is a stream, write the raw]' \
    '--filtered-stream-data' \
    '--show-npages[Print the number of pages in the input file on a line by itself]' \
    '--show-pages[Show the object and generation number for each page dictionary object]' \
    '--with-images[When used with --show-pages, also shows the object and generation numbers]' \
    '--json' \
    '--json-help' \
    '--json-key' \
    '--json-object' \
    '--json-stream-data' \
    '--json-stream-prefix[when --json-output is specified, in which case the default is "inline"]' \
    '--json-input[Treat the input file as a JSON file in qpdf JSON format]' \
    '--update-from-json' \
    '--static-id[Use a fixed value for the document ID. This is intended for testing only]' \
    '--static-aes-iv[Use a static initialization vector for AES-CBC]' \
    '--linearize-pass1' \
    '--test-json-schema[This is used by qpdf'\''s test suite to check consistency]' \
    '--report-memory-usage[This is used by qpdf'\''s performance test suite to report the maximum usage]'
}

_qpdf
