Sha256: e2689e9bd9ee33231c5f3dfb875ef89cfb9bf823c5acd433aee69a9ec9573f7e
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require "libreconv/version" module Libreconv def self.convert(source, target, soffice_command = nil) Converter.new(source, target, soffice_command).convert end class Converter attr_accessor :soffice_command def initialize(source, target_path, soffice_command = nil) @source = source @target_path = target_path @soffice_command = soffice_command determine_soffice_command unless @soffice_command && File.exists?(@soffice_command) raise IOError, "Can't find Libreoffice or Openoffice executable." end unless File.exists?(source) raise IOError, "Source file (#{source}) does not exist." end end def convert cmd = "#{@soffice_command} --headless --convert-to pdf #{@source} -outdir #{@target_path}" system("#{cmd} > /dev/null") end private def determine_soffice_command unless @soffice_command @soffice_command ||= which("soffice") @soffice_command ||= which("soffice.bin") end end def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable? exe end end return nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
libreconv-0.5.0 | lib/libreconv.rb |