lib/hexapdf/cli/command.rb in hexapdf-0.30.0 vs lib/hexapdf/cli/command.rb in hexapdf-0.31.0
- old
+ new
@@ -99,10 +99,21 @@
# Returns a hash with HexaPDF::Document options based on the given password and the option
# switches.
def pdf_options(password)
hash = {decryption_opts: {password: password}, config: {}}
HexaPDF::GlobalConfiguration['filter.predictor.strict'] = command_parser.strict
+ HexaPDF::GlobalConfiguration['filter.flate.on_error'] =
+ if command_parser.strict
+ proc { true }
+ else
+ proc do |_, error|
+ if command_parser.verbosity_info?
+ $stderr.puts "Ignoring error in flate encoded stream: #{error}"
+ end
+ false
+ end
+ end
hash[:config]['parser.try_xref_reconstruction'] = !command_parser.strict
hash[:config]['parser.on_correctable_error'] =
if command_parser.strict
proc { true }
else
@@ -118,18 +129,22 @@
end
# Writes the document to the given file or does nothing if +out_file+ is +nil+.
def write_document(doc, out_file, incremental: false)
if out_file
+ doc.trailer.update_id
doc.validate(auto_correct: true) do |msg, correctable, object|
if command_parser.strict && !correctable
raise "Validation error for object (#{object.oid},#{object.gen}): #{msg}"
elsif command_parser.verbosity_info?
$stderr.puts "#{correctable ? 'Corrected' : 'Ignored'} validation problem " \
"for object (#{object.oid},#{object.gen}): #{msg}"
end
end
+ if command_parser.verbosity_info?
+ puts "Creating output document #{out_file}"
+ end
doc.write(out_file, validate: false, incremental: incremental)
end
end
# Checks whether the given output file exists and raises an error if it does and
@@ -329,10 +344,10 @@
end_nr = [PAGE_MAP[$2, count], count].min - 1
step = ($3 ? $3.to_i : 1) * (start_nr > end_nr ? -1 : 1)
rotation = ROTATE_MAP[$4]
start_nr.step(to: end_nr, by: step) {|n| arr << [n, rotation] }
else
- raise OptionParser::InvalidArgument, "invalid page range format: #{str}"
+ raise OptionParser::InvalidArgument, "invalid page range format: #{str.inspect}"
end
end
end
# Reads a password from the standard input and falls back to the console if needed.