Class: HexaPDF::CLI::Modify
- Defined in:
- lib/hexapdf/cli/modify.rb
Overview
Modifies a PDF file:
-
Decrypts or encrypts the resulting output PDF file.
-
Generates or deletes object and cross-reference streams.
-
Optimizes the output PDF by merging the revisions of a PDF file and removes unused entries.
See: HexaPDF::Task::Optimize
Instance Method Summary collapse
-
#execute(in_file, out_file) ⇒ Object
:nodoc:.
-
#initialize ⇒ Modify
constructor
:nodoc:.
Methods included from Command::Extensions
Constructor Details
#initialize ⇒ Modify
:nodoc:
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 |
# File 'lib/hexapdf/cli/modify.rb', line 49 def initialize #:nodoc: super('modify', takes_commands: false) short_desc("Modify a PDF file") long_desc(" This command modifies a PDF file. It can be used to select pages that should appear in\n the output file and/or rotate them. The output file can also be encrypted/decrypted and\n optimized in various ways.\n EOF\n\n @password = nil\n @pages = '1-e'\n @embed_files = []\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(\"-i\", \"--pages PAGES\", \"The pages of the input file that should be used \" \\\n \"(default: 1-e)\") do |pages|\n @pages = pages\n end\n options.on(\"-e\", \"--embed FILE\", String, \"Embed the file into the output file (can be \" \\\n \"used multiple times)\") do |file|\n @embed_files << file\n end\n define_optimization_options\n define_encryption_options\nend\n".gsub!(/^ */, '')) |
Instance Method Details
#execute(in_file, out_file) ⇒ Object
:nodoc:
78 79 80 81 82 83 84 85 86 |
# File 'lib/hexapdf/cli/modify.rb', line 78 def execute(in_file, out_file) #:nodoc: maybe_raise_on_existing_file(out_file) with_document(in_file, password: @password, out_file: out_file) do |doc| arrange_pages(doc) unless @pages == '1-e' .each {|file| doc.files.add(file, embed: true)} (doc) (doc) end end |