Skip to content

Commit c0acbeb

Browse files
committed
Alternative converter
1 parent 019eafb commit c0acbeb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

examples/alternative_converter.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'convert_api'
2+
require 'tmpdir'
3+
4+
ConvertApi.configure do |config|
5+
config.api_secret = ENV['CONVERT_API_SECRET'] # your api secret
6+
end
7+
8+
# Example of saving Word docx to PDF using OpenOffice converter
9+
# https://www.convertapi.com/doc-to-pdf/openofficetopdf
10+
11+
# Use upload IO wrapper to upload file only once to the API
12+
upload_io = ConvertApi::UploadIO.new(File.open('files/test.docx'))
13+
14+
saved_files = ConvertApi
15+
.convert('pdf', File: upload_io, converter: 'openofficetopdf')
16+
.save_files(Dir.tmpdir)
17+
18+
puts "The PDF saved to: #{saved_files}"

lib/convert_api/task.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ def run
1515

1616
from_format = @from_format || detect_format(params)
1717
read_timeout = @conversion_timeout + config.conversion_timeout_delta
18+
converter = params[:converter] ? "/converter/#{params[:converter]}" : ''
1819

1920
response = ConvertApi.client.post(
20-
"convert/#{from_format}/to/#{@to_format}",
21+
"convert/#{from_format}/to/#{@to_format}#{converter}",
2122
params,
2223
read_timeout: read_timeout
2324
)

0 commit comments

Comments
 (0)