@@ -16,7 +16,7 @@ def osx?
16
16
def linux?
17
17
!!HOST_OS . match ( /linux/i )
18
18
end
19
-
19
+
20
20
# The first line of the help output holds the name and version number
21
21
# of the office software to be used for extraction.
22
22
def version_string
@@ -35,10 +35,10 @@ def libre_office?
35
35
def open_office?
36
36
!!version_string . match ( /^OpenOffice.org/ )
37
37
end
38
-
38
+
39
39
# A set of default locations to search for office software
40
40
# These have been extracted from JODConverter. Each listed
41
- # path should contain a directory "program" which in turn
41
+ # path should contain a directory "program" which in turn
42
42
# contains the "soffice" executable.
43
43
# see: https://github.com/mirkonasato/jodconverter/blob/master/jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java#L63-L91
44
44
def office_search_paths
@@ -69,7 +69,7 @@ def office_search_paths
69
69
end
70
70
search_paths
71
71
end
72
-
72
+
73
73
# Identify the path to a working office executable.
74
74
def office_executable
75
75
paths = office_search_paths
@@ -78,10 +78,10 @@ def office_executable
78
78
# raise an error if that path isn't valid, otherwise, add
79
79
# it to the front of our search paths.
80
80
if ENV [ 'OFFICE_PATH' ]
81
- raise ArgumentError , "No such file or directory #{ ENV [ 'OFFICE_PATH' ] } " unless File . exists ? ENV [ 'OFFICE_PATH' ]
81
+ raise ArgumentError , "No such file or directory #{ ENV [ 'OFFICE_PATH' ] } " unless File . exist ? ENV [ 'OFFICE_PATH' ]
82
82
paths . unshift ( ENV [ 'OFFICE_PATH' ] )
83
83
end
84
-
84
+
85
85
# The location of the office executable is OS dependent
86
86
path_pieces = [ "soffice" ]
87
87
if windows?
@@ -91,32 +91,32 @@ def office_executable
91
91
else
92
92
path_pieces += [ [ "program" , "soffice" ] ]
93
93
end
94
-
94
+
95
95
# Search for the first suitable office executable
96
96
# and short circuit an executable is found.
97
97
paths . each do |path |
98
- if File . exists ? path
98
+ if File . exist ? path
99
99
@@executable ||= path unless File . directory? path
100
100
path_pieces . each do |pieces |
101
101
check_path = File . join ( path , pieces )
102
- @@executable ||= check_path if File . exists ? check_path
102
+ @@executable ||= check_path if File . exist ? check_path
103
103
end
104
104
end
105
105
break if @@executable
106
106
end
107
107
raise OfficeNotFound , "No office software found" unless @@executable
108
108
@@executable
109
109
end
110
-
110
+
111
111
# Used to specify the office location for JODConverter
112
112
def office_path
113
113
File . dirname ( File . dirname ( office_executable ) )
114
114
end
115
-
115
+
116
116
# Convert documents to PDF.
117
117
def extract ( docs , opts )
118
118
out = opts [ :output ] || '.'
119
- FileUtils . mkdir_p out unless File . exists ?( out )
119
+ FileUtils . mkdir_p out unless File . exist ?( out )
120
120
[ docs ] . flatten . each do |doc |
121
121
ext = File . extname ( doc )
122
122
basename = File . basename ( doc , ext )
@@ -128,7 +128,7 @@ def extract(docs, opts)
128
128
if libre_office?
129
129
# Set the LibreOffice user profile, so that parallel uses of cloudcrowd don't trip over each other.
130
130
ENV [ 'SYSUSERCONFIG' ] = "file://#{ File . expand_path ( escaped_out ) } "
131
-
131
+
132
132
options = "--headless --invisible --norestore --nolockcheck --convert-to pdf --outdir #{ escaped_out } #{ escaped_doc } "
133
133
cmd = "#{ office_executable } #{ options } 2>&1"
134
134
result = `#{ cmd } ` . chomp
@@ -147,9 +147,9 @@ def extract(docs, opts)
147
147
LOGGING = "-Djava.util.logging.config.file=#{ ESCAPED_ROOT } /vendor/logging.properties"
148
148
149
149
HEADLESS = "-Djava.awt.headless=true"
150
-
150
+
151
151
private
152
-
152
+
153
153
# Runs a Java command, with quieted logging, and the classpath set properly.
154
154
def run_jod ( command , pdfs , opts , return_output = false )
155
155
0 commit comments