Class: HexaPDF::CLI::Files
- Defined in:
- lib/hexapdf/cli/files.rb
Overview
Lists or extracts embedded files from a PDF file.
See: HexaPDF::Type::EmbeddedFile
Instance Method Summary collapse
-
#execute(pdf) ⇒ Object
:nodoc:.
-
#initialize ⇒ Files
constructor
:nodoc:.
Methods included from Command::Extensions
Constructor Details
#initialize ⇒ Files
:nodoc:
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 |
# File 'lib/hexapdf/cli/files.rb', line 47 def initialize #:nodoc: super('files', takes_commands: false) short_desc("List or extract embedded files from a PDF file") long_desc(<<~EOF) If the option --extract is not given, the available files are listed with their names and indices. The --extract option can then be used to extract one or more files. EOF .on("--extract [a,b,c,...]", "-e [a,b,c,...]", Array, "The indices of the files that should be extracted. Use 0 or no argument to " \ "extract all files.") do |indices| @indices = (indices ? indices.map(&:to_i) : [0]) end .on("--[no-]search", "-s", "Search the whole PDF instead of the " \ "standard locations (default: false)") do |search| @search = search end .on("--password PASSWORD", "-p", String, "The password for decryption. Use - for reading from standard input.") do |pwd| @password = (pwd == '-' ? read_password : pwd) end @indices = [] @password = nil @search = false end |
Instance Method Details
#execute(pdf) ⇒ Object
:nodoc:
74 75 76 77 78 79 80 81 82 |
# File 'lib/hexapdf/cli/files.rb', line 74 def execute(pdf) #:nodoc: with_document(pdf, password: @password) do |doc| if @indices.empty? list_files(doc) else extract_files(doc) end end end |