Class: HexaPDF::CLI::Files

Inherits:
Command
  • Object
show all
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

Methods included from Command::Extensions

#help, #help_banner

Constructor Details

#initializeFiles

: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("    If the option --extract is not given, the available files are listed with their names and\n    indices. The --extract option can then be used to extract one or more files.\n  EOF\n\n  options.on(\"--extract [a,b,c,...]\", \"-e [a,b,c,...]\", Array,\n             \"The indices of the files that should be extracted. Use 0 or no argument to \" \\\n             \"extract all files.\") do |indices|\n    @indices = (indices ? indices.map(&:to_i) : [0])\n  end\n  options.on(\"--[no-]search\", \"-s\", \"Search the whole PDF instead of the \" \\\n             \"standard locations (default: false)\") do |search|\n    @search = search\n  end\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\n  @indices = []\n  @password = nil\n  @search = false\nend\n")

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