Tornado - Create a PDF using Ruby via API

This example shows how to generate a PDF from a DOC template using Ruby.  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 Ruby example calls the local Docmosis Tornado service to create a PDF document
# from the default template (WelcomeTemplate.doc).
# To run:
#  1) install the rest-client gem if you haven't already (see below)
#  2) run the code
# Note, this example uses the rest-client Ruby component.
# To install: gem install rest-client
# Home page
# Copyright Docmosis 2015

require 'rest-client'
require 'date'
require 'json'

# RESTFul service URL
$DWS_RENDER_URL = "http://localhost:8080/api/render"
# Your account key

# The template to use
# NOTE that it has to be defined in your account with the same name specified here
$TEMPLATE = "WelcomeTemplate.doc" # Change with your actual template name

# The output file name

def msg (message)

# Set the web proxy to use from the environment variable.
# The settings for proxy are site-dependent so you may need to
# adjust this
RestClient.proxy = ENV['http_proxy'];$DWS_RENDER_URL,
    'accessKey' => $ACCESS_KEY,
    'templateName' => $TEMPLATE,
    'outputName' => $OUTPUT,
    'data' => {
                'date' =>,
                'message' => 'This Tornado Document Engine is working great!',
}.to_json, :content_type => :json) {|response, request, result, &block|
    case response.code
    when 200$OUTPUT,"wb"){|f|f.syswrite(response.body)}
        puts "\"#{$OUTPUT}\" created"
        # 4XX errors - client errors - something needs to be corrected in the request
        # 5XX errors - server side errors - possibly worth a retry

        # show error response (details)
        puts "Error response:\n\n#{response.code} #{response}\n\n"
        response.return!(request, result, &block)


Invalid Input

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam. Please also consider contacting 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

API Overview

Docmosis offers a high-performance, template-based PDF generation API. Suitable for use with custom software applications built using Java, C#/.Net, Python, Ruby and more. See a side-by-side comparison of the API for our SaaS and self-hosted products.

Related items