Skip to content

Commit 856b122

Browse files
author
Doug Mayer
committed
Add timeout option to JODConverter.
Original work by documentcloud#34 with modification to not use a default timeout (causing no change from existing functionality).
1 parent 63642eb commit 856b122

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ <h2 id="usage">Usage</h2>
233233
<b>xls</b> and so on, as well as <b>html</b>, <b>odf</b>, <b>rtf</b>, <b>swf</b>, <b>svg</b>, and <b>wpd</b>.
234234
The first time that you convert a new file type, LibreOffice will lazy-load
235235
the code that processes it &mdash; subsequent conversions will be much faster.
236+
<br />
237+
The <tt>--timeout</tt> flag may be used to set the number of seconds before
238+
JODConverter's "error on timeout" exception. Useful when you convert very large documents.
236239
</p>
237240
<pre>
238241
docsplit pdf documentation/*.html</pre>

lib/docsplit/command_line.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def parse_options
101101
opts.on('-r', '--rolling', 'generate images from each previous image') do |r|
102102
@options[:rolling] = true
103103
end
104+
opts.on('-t', '--timeout', 'Timeout for PDF extraction from OpenOffice-supported document format') do |t|
105+
@options[:timeout] = t
106+
end
104107
opts.on_tail('-v', '--version', 'display docsplit version') do
105108
puts "Docsplit version #{Docsplit::VERSION}"
106109
exit
@@ -120,4 +123,4 @@ def parse_options
120123

121124
end
122125

123-
end
126+
end

lib/docsplit/pdf_extractor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def office_path
112112
# Convert documents to PDF.
113113
def extract(docs, opts)
114114
out = opts[:output] || '.'
115+
timeout = opts[:timeout]
115116
FileUtils.mkdir_p out unless File.exists?(out)
116117
[docs].flatten.each do |doc|
117118
ext = File.extname(doc)
@@ -132,6 +133,7 @@ def extract(docs, opts)
132133
true
133134
else # open office presumably, rely on JODConverter to figure it out.
134135
options = "-jar #{ESCAPED_ROOT}/vendor/jodconverter/jodconverter-core-3.0-beta-4.jar -r #{ESCAPED_ROOT}/vendor/conf/document-formats.js"
136+
options += "-t #{timeout}" if timeout
135137
run_jod "#{options} #{escaped_doc} #{escaped_out}/#{escaped_basename}.pdf", [], {}
136138
end
137139
end

0 commit comments

Comments
 (0)