Class: HexaPDF::CLI::Form
- Defined in:
- lib/hexapdf/cli/form.rb
Overview
Processes a PDF that contains an interactive form (AcroForm).
Instance Method Summary collapse
-
#execute(in_file, out_file = nil) ⇒ Object
:nodoc:.
-
#initialize ⇒ Form
constructor
:nodoc:.
Methods included from Command::Extensions
Constructor Details
#initialize ⇒ Form
:nodoc:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hexapdf/cli/form.rb', line 46 def initialize #:nodoc: super('form', takes_commands: false) short_desc("Show form fields and fill out a form") long_desc(" Use this command to process interactive PDF forms.\n\n If the the output file name is not given, all form fields are listed in page order. Use\n the global --verbose option to show additional information like field type and location.\n\n If the output file name is given, the fields can be interactively filled out. By\n additionally using the --template option, the data for the fields is read from the given\n template file instead of the standard input.\n EOF\n\n options.on(\"--password PASSWORD\", \"-p\", String,\n \"The password for decryption. Use - for reading from standard input.\") do |pwd|\n @password = (pwd == '-' ? read_password : pwd)\n end\n options.on(\"--template TEMPLATE_FILE\", \"-t TEMPLATE_FILE\",\n \"Use the template file for the field values\") do |template|\n @template = template\n end\n options.on(\"--[no-]viewer-override\", \"Let the PDF viewer override the visual \" \\\n \"appearance. Default: use setting from input PDF\") do |need_appearances|\n @need_appearances = need_appearances\n end\n options.on(\"--[no-]incremental-save\", \"Append the changes instead of rewriting the \" \\\n \"whole file. Default: true\") do |incremental|\n @incremental = incremental\n end\n\n @password = nil\n @template = nil\n @need_appearances = nil\n @incremental = true\nend\n") |
Instance Method Details
#execute(in_file, out_file = nil) ⇒ Object
:nodoc:
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/hexapdf/cli/form.rb', line 83 def execute(in_file, out_file = nil) #:nodoc: maybe_raise_on_existing_file(out_file) if out_file with_document(in_file, password: @password, out_file: out_file, incremental: @incremental) do |doc| if !doc.acro_form raise "This PDF doesn't contain an interactive form" elsif out_file doc.acro_form[:NeedAppearances] = @need_appearances unless @need_appearances.nil? if @template fill_form_with_template(doc) else fill_form(doc) end else list_form_fields(doc) end end end |