Class: Libis::Format::Converter::PdfConverter

Inherits:
Base
  • Object
show all
Defined in:
lib/libis/format/converter/pdf_converter.rb

Overview

noinspection DuplicatedCode

Instance Attribute Summary

Attributes inherited from Base

#flags, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

category, #check_file_exist, inherited, #initialize, #using_temp, using_temp

Constructor Details

This class inherits a constructor from Libis::Format::Converter::Base

Class Method Details

.input_typesObject



14
15
16
# File 'lib/libis/format/converter/pdf_converter.rb', line 14

def self.input_types
  [:PDF]
end

.output_types(format = nil) ⇒ Object



18
19
20
21
# File 'lib/libis/format/converter/pdf_converter.rb', line 18

def self.output_types(format = nil)
  return [] unless input_types.include?(format) if format
  [:PDFA]
end

Instance Method Details

#convert(source, target, format, opts = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/libis/format/converter/pdf_converter.rb', line 23

def convert(source, target, format, opts = {})
  super

  result = pdf_to_pdfa(source, target)
  return nil unless result

  result

end

#pdf_to_pdfa(source, target) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/libis/format/converter/pdf_converter.rb', line 33

def pdf_to_pdfa(source, target)

  using_temp(target) do |tmpname|
    result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
    if result[:status] != 0
      error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
      next nil
    else
      warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
    end
    tmpname
  end

end