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
-
#initialize ⇒ Modify
constructor
A new instance of Modify.
Methods included from Command::Extensions
Constructor Details
#initialize ⇒ Modify
Returns a new instance of Modify.
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 82 83 |
# File 'lib/hexapdf/cli/modify.rb', line 51 def initialize #:nodoc: super('modify', takes_commands: false) short_desc("Modify a PDF file") long_desc(<<~EOF) This command modifies a PDF file. It can be used, for example, to select pages that should appear in the output file and/or rotate them. The output file can also be encrypted/decrypted and optimized in various ways. EOF @password = nil @pages = '1-e' @embed_files = [] @annotation_mode = nil .on("--password PASSWORD", "-p", String, "The password for decryption. Use - for reading from standard input.") do |pwd| @password = (pwd == '-' ? read_password : pwd) end .on("-i", "--pages PAGES", "The pages of the input file that should be used " \ "(default: 1-e)") do |pages| @pages = pages end .on("-e", "--embed FILE", String, "Embed the file into the output file (can be " \ "used multiple times)") do |file| @embed_files << file end .on("--annotations MODE", [:remove, :flatten], "Handling of annotations (either " \ "remove or flatten)") do |mode| @annotation_mode = mode end end |
Instance Method Details
#execute(in_file, out_file) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hexapdf/cli/modify.rb', line 85 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' handle_annotations(doc) @embed_files.each {|file| doc.files.add(file, embed: true) } (doc) (doc) end end |