forked from ConvertAPI/convertapi-library-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversions_chaining.py
More file actions
22 lines (13 loc) · 816 Bytes
/
Copy pathconversions_chaining.py
File metadata and controls
22 lines (13 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import convertapi
import os
import tempfile
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
# Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
# https://www.convertapi.com/doc/chaining
print('Converting PDF to JPG and compressing result files with ZIP')
jpg_result = convertapi.convert('jpg', { 'File': 'files/test.pdf' })
print("Conversions done. Cost: %s. Total files created: %s" % (jpg_result.conversion_cost, len(jpg_result.files)))
zip_result = convertapi.convert('zip', { 'Files': jpg_result.files })
print("Conversions done. Cost: %s. Total files created: %s" % (zip_result.conversion_cost, len(zip_result.files)))
saved_files = zip_result.save_files(tempfile.gettempdir())
print("File saved to %s" % saved_files)