Sha256: 9499d73c3039c5fbf5021a4caffba694b75d00877e4dba130a06f923332127e2

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

# encoding: utf-8

require_relative 'base'

require 'libis/format/tool/pdf_metadata'

module Libis
  module Format
    module Converter

      # noinspection DuplicatedCode
      class PdfMetadata < Libis::Format::Converter::Base

        def self.input_types
          [:PDF]
        end

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

        def title(v)
          @options[:title] = v.blank? ? nil : v
        end

        def author(v)
          @options[:author] = v.blank? ? nil : v
        end

        def creator(v)
          @options[:creator] = v.blank? ? nil : v
        end

        def keywords(v)
          @options[:keywords] = v.blank? ? nil : v
        end

        def subject(v)
          @options[:subject] = v.blank? ? nil : v
        end

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

          result = nil

          unless @options.empty?
            result = convert_pdf(source, target)
            return nil unless result
          end

          result

        end

        def convert_pdf(source, target)

          using_temp(target) do |tmpname|
            result = Libis::Format::Tool::PdfMetadata.run(
                source, tmpname,
                @options.map {|k, v|
                  if v.nil?
                    nil
                  else
                    ["--#{k}", v.to_s]
                  end}.compact.flatten
            )
            unless result[:err].empty?
              error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
              next nil
            end
            tmpname
          end

        end

      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
libis-format-2.0.5 lib/libis/format/converter/pdf_metadata.rb