Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/libreconv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ConversionFailedError < StandardError; end
# @raise [URI::Error] When URI parsing error.
# @raise [Net::ProtocolError] If source URL checking failed.
# @raise [ConversionFailedError] When soffice command execution error.
def self.convert(source, target, soffice_command = nil, convert_to = nil)
Converter.new(source, target, soffice_command, convert_to).convert
def self.convert(source, target, soffice_command = nil, convert_to = nil,filter = nil)
Converter.new(source, target, soffice_command, convert_to,filter).convert
end

class Converter
Expand All @@ -34,12 +34,13 @@ class Converter
# @raise [IOError] If invalid source file/URL or soffice command not found.
# @raise [URI::Error] When URI parsing error.
# @raise [Net::ProtocolError] If source URL checking failed.
def initialize(source, target, soffice_command = nil, convert_to = nil)
def initialize(source, target, soffice_command = nil, convert_to = nil,filter = nil)
@source = check_source_type(source)
@target = target
@soffice_command = soffice_command || which('soffice') || which('soffice.bin')
@convert_to = convert_to || 'pdf'

@infilter = filter

ensure_soffice_exists
end

Expand Down Expand Up @@ -92,6 +93,7 @@ def build_command(tmp_pipe_path, target_path)
"--accept=\"pipe,name=#{File.basename(tmp_pipe_path)};url;StarOffice.ServiceManager\"",
"-env:UserInstallation=#{build_file_uri(tmp_pipe_path)}",
'--headless',
check_filter, #Add extra infilter
'--convert-to', @convert_to,
escaped_source,
'--outdir', target_path
Expand All @@ -106,6 +108,12 @@ def escaped_source
@source.to_s
end

#If filter is nil/not provided return empty string.else return with --infilter param
def check_filter
return "--infilter=#{@infilter}" if @infilter
return ""
end

# @return [String]
def escaped_source_path
@source.is_a?(URI::Generic) ? @source.path : @source
Expand Down