File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 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 } "
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments