Tornado Render using Python

This example shows how to generate a PDF from a DOC template using Python.  It calls the Docmosis REST API to merge the data with the template and stream the result back.

The sample code includes the instructions to get started. You will need a Free Trial to install and run Tornado.

# This example shows how to use Python to call a local Docmosis Tornado service to render a PDF from the default WelcomeTemplate.doc template.

import requests
import json
import datetime

accessKey=''

dataStr = '{"message":"This Tornado Document Engine is working great!", "date":"' + datetime.datetime.now().strftime("%Y/%m/%d") + '"}'
payload = '{"accessKey": "' + accessKey + '", "templateName":"samples/WelcomeTemplate.doc", "outputName":"myWelcome.pdf", "data":' + dataStr + '}'

headers = {'content-type': 'application/json'}
r = requests.post("http://localhost:8080/api/render", data=payload, headers = headers)

if r.status_code == requests.codes.ok:

  with open('myWelcome.pdf', 'wb') as fd:
    for chunk in r.iter_content(4096):
        fd.write(chunk)
  print("Saved to myWelcome.pdf");
else:
  print("Failed");
  print(r.text)
 

Feedback

Invalid Input

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam. Please also consider contacting support@docmosis.com if you need help with this article.

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam.

Invalid Input

Applies To

Docmosis-Java Tornado Cloud
Version(s) - ALL -