Skip to content

Commit 789d3ed

Browse files
author
Laurynas Butkus
committed
Allow passing alternative converter
1 parent 792e9e0 commit 789d3ed

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

convertapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '1.1.1'
1+
__version__ = '1.2.0'
22

33
from .exceptions import *
44
from .client import Client

convertapi/task.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def run(self):
2323
timeout = self.timeout + convertapi.conversion_timeout_delta
2424
path = "convert/%s/to/%s" % (from_format, self.to_format)
2525

26+
if 'converter' in params:
27+
path += "/converter/%s" % (params['converter'])
28+
2629
response = convertapi.client.post(path, params, timeout = timeout)
2730

2831
return Result(response)

examples/alternative_converter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import convertapi
2+
import os
3+
import tempfile
4+
5+
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
6+
7+
# Example of saving Word docx to PDF using OpenOffice converter
8+
# https://www.convertapi.com/doc-to-pdf/openoffice
9+
10+
upload_io = convertapi.UploadIO(open('files/test.docx', 'rb'))
11+
params = { 'File': upload_io, 'converter': 'openoffice' }
12+
13+
saved_files = convertapi.convert('pdf', params).save_files(tempfile.gettempdir())
14+
15+
print("The PDF saved to %s" % saved_files)

tests/test_convertapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def test_convert_file(self):
2323
assert result.save_files(tempfile.gettempdir())
2424
assert result.conversion_cost > 0
2525

26+
def test_convert_file_alternative(self):
27+
result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx', 'converter': 'openoffice' })
28+
assert result.save_files(tempfile.gettempdir())
29+
assert result.conversion_cost > 0
30+
2631
def test_convert_file_url(self):
2732
result = convertapi.convert('pdf', { 'File': 'https://cdn.convertapi.com/cara/testfiles/document.docx?test=1' })
2833
assert result.conversion_cost > 0

0 commit comments

Comments
 (0)