-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsync.py
More file actions
42 lines (38 loc) · 1.57 KB
/
sync.py
File metadata and controls
42 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This example demonstrates creating a PDF using common options and saving it
# to a place on the filesystem.
#
# It is created synchronously, which means DocRaptor will render it for up to
# 60 seconds. It is slightly simpler than making documents using the async
# interface but making many documents in parallel or very large documents with
# lots of assets will require the async api.
#
# DocRaptor supports many CSS and API options for output customization. Visit
# https://docraptor.com/documentation/ for full details.
#
# You can run this example with: python sync.py
import docraptor
doc_api = docraptor.DocApi()
# this key works in test mode!
doc_api.api_client.configuration.username = 'YOUR_API_KEY_HERE'
try:
response = doc_api.create_doc({
'test': True, # test documents are free but watermarked
'document_type': 'pdf',
'document_content': '<html><body>Hello World!</body></html>',
# 'document_url': 'https://docraptor.com/examples/invoice.html',
# 'javascript': True,
# 'prince_options': # {
# 'media': 'print', # @media 'screen' or 'print' CSS
# 'baseurl': 'https://yoursite.com', # the base URL for any relative URLs
# },
})
# create_doc() returns a binary string
with open('github-sync.pdf', 'w+b') as f:
binary_formatted_response = bytearray(response)
f.write(binary_formatted_response)
f.close()
print('Successfully created github-sync.pdf!')
except docraptor.rest.ApiException as error:
print(error.status)
print(error.reason)
print(error.body)