From 797deb4e86aadc7bc53630e16c2058e06ff4780a Mon Sep 17 00:00:00 2001 From: Atharva Chakankar <58178208+atha10@users.noreply.github.com> Date: Tue, 26 Mar 2024 08:40:53 +0530 Subject: [PATCH] Added infilter param so using filter can convert pdf into other document --- lib/libreconv.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/libreconv.rb b/lib/libreconv.rb index da81a97..28cc950 100644 --- a/lib/libreconv.rb +++ b/lib/libreconv.rb @@ -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 @@ -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 @@ -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 @@ -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