{% extends "silpa.html" %} {% block modulescript %} {% endblock %} {% block content %}
This is an experimental online service based on PyPDFLib library in development. This library projects objective is to develop an opensource pdf rendering library which can support all complex scripts. It is in development and this service is not bug-free now.
You can use Silpa python APIs to renedr a custom text to any image format or PDF. After installing silpa, refer the following example for using the api. The text can be in any script, including Right to Left scripts.
from silpa.modules import render
render=render.getInstance()
#Render the text to SVG format. width=100, height= 200 pixels
render.render_text("Your text goes here", "svg", 100,200)
#Render the text to png format. width=100, height will be automatcally set based the content size
render.render_text("Your text goes here", "png", 100 ,0)
# Render the text to a PDF
render.render_text("Your text goes here", "pdf", 500 , 500)
The render_text method return the name of the generated image.(TODO: Make the path of the image configurable)
You will require JSON RPC client from here: http://json-rpc.org/wiki/python-json-rpc
from jsonrpc import ServiceProxy
proxy = ServiceProxy("http://localhost/silpa/JSONRPC")
print s.modules.Render.render_text("Your text goes here", "svg", 100,200)
A sample PHP client to use the Silpa's JSON RPC service is given below.
define ('HOSTNAME', 'http://silpa.smc.org.in/JSONRPC');
$url = HOSTNAME;
// Open the Curl session
$session = curl_init($url);
// If it's a POST, put the POST data in the body
$postvars = '{"method": "modules.Render.render_text", "params": ["Your text goes here", "png", 100,100], "id":"jsonrpc"}';
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$json = curl_exec($session);
// The web service returns json. Set the Content-Type appropriately
header("Content-Type: application/json");
echo $json;
$obj = json_decode($json,false);
$result = $obj->{"result"};
echo $result;
curl_close($session);
The result will contain the image name. the image can be accessed by http://silpa.smc.org.in/Render?image=abcd.png
$postvars = '{"method": "modules.Render.wiki2pdf", "params": ["http://en.wikipedia.org/wiki/Kerala"], "id":"jsonrpc"}';