Class: HexaPDF::CLI::Images
- Defined in:
- lib/hexapdf/cli/images.rb
Overview
Lists or extracts images from a PDF file.
See: HexaPDF::Type::Image
Instance Method Summary collapse
-
#execute(pdf) ⇒ Object
:nodoc:.
-
#initialize ⇒ Images
constructor
:nodoc:.
Methods included from Command::Extensions
Constructor Details
#initialize ⇒ Images
:nodoc:
45 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 |
# File 'lib/hexapdf/cli/images.rb', line 45 def initialize #:nodoc: super('images', takes_commands: false) short_desc("List or extract images from a PDF file") long_desc(" If the option --extract is not given, the available images are listed with their index and\n additional information, sorted by page number. The --extract option can then be used to\n extract one or more images, saving them to files called `prefix-n.ext` where the prefix\n can be set via --prefix, n is the index and ext is either png, jpg or jpx.\n EOF\n\n options.on(\"--extract [A,B,C,...]\", \"-e [A,B,C,...]\", Array,\n \"The indices of the images that should be extracted. Use 0 or no argument to \" \\\n \"extract all images.\") do |indices|\n @indices = (indices ? indices.map(&:to_i) : [0])\n end\n options.on(\"--prefix PREFIX\", String,\n \"The prefix to use when saving images. May include directories. Default: \" \\\n \"image.\") do |prefix|\n @prefix = prefix\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 @prefix = 'image'\n @password = nil\n @search = false\nend\n") |
Instance Method Details
#execute(pdf) ⇒ Object
:nodoc:
80 81 82 83 84 85 86 87 88 |
# File 'lib/hexapdf/cli/images.rb', line 80 def execute(pdf) #:nodoc: with_document(pdf, password: @password) do |doc| if @indices.empty? list_images(doc) else extract_images(doc) end end end |