fudok
v1.0.0
Published
Client API for Fudok PDF templating
Downloads
12
Readme
Node.js client API for Fudok
This Node.js API allows to call PDF templating features exposed by Fudok.
Get started
This package can be installed as NPM package: npm install fudok
Then fudok
module can be required in your Node.js code: var fudok = require("fudok")
The main function to merge data (e.g. form submission) with PDF template managed on Fudok is fudok.merge
:
var fudok = require("fudok");
fudok.merge(options/* see details bellow */);
See: Online demo
Example
Some examples using this module are available in the repository: see simple example.
var fudok = require("fudok");
fudok.merge({
// Mandatory options
token:"a610e9b1048499110433bb790489303a07182aac"/*replace by your token*/,
template:"ca62e08d-2082-4cd4-837c-d46a362091e3"/*replace by your template*/,
success: function(res){ // Success handler
console.log("Will save merged document as document.pdf file");
res.pipe(fs.createWriteStream("document.pdf"));
},
error: function(httpStatus){ // Optional, custom error handler
console.error("Oups! Got an error: " + httpStatus)
},
parameters: { // Name-value pairs corresponding to template areas
'firstName': "First name"
}
});
API reference
The module is exposing following Fudok functions.
merge
.merge(options)
: Merge values with specified template;
Object options
is expecting following properties.
token
: Fudok application token (string
).template
: ID of Fudok template (string
).parameters
: Name/value pairs to be merged with areas (object
).success
: Success callback, is given a HTTP response as argument; Optional function, if undefined default handler (console.log
) is used.error
: Error callback, is given HTTP error code (int) as argument; Optional function, if undefined default handler (console.error
) is used.
Application token and template ID are visible in Integration tab on Template screen of Fudok management.
See code sample
auth
.auth(options)
: Authenticate and get the administration token to be able to manage the corresponding Fudok account.
email
: Fudok login (string
).password
: Fudok password (string
, cleartext)success
: Success callback, is given the admin token as argument; Optional, if undefined default handler (console.log) is used.- error: Error callback, is given error details as argument (e.g.
{'code':123, 'cause':"Error cause"}
; Optional, if undefined default handler (console.error) is used.
See code sample
Template list
.templateList(options)
: List the templates of Fudok account specified by the given administration token.
var dok = require("fudok");
dok.templateList({
// replace by your admin token, see `dok.auth`
token: "c64ca212064c8588b9c5f4a2d9165399b99aa83c",
success: function(res){ // Success handler
// res = http://nodejs.org/api/http.html#http_event_response
console.log("List of Fudok templates: " + JSON.stringify(res));
},
error: function(httpStatus){ // Optional, custom error handler
console.error("Oups! Got an error: " + httpStatus)
}
});
The success handler is given an object with following properties.
```javascript
{
"token": "app_token",
"activePlan": { "credits":1 },
"templates": [
{ "id": "tmpl-1", "name": "Template #1", "expiration":1418833775372 },
{ "id": "tmpl-2", "name": "Second template" },
{ "id": "tmpl-3", "name": "The third one" },
{ "id": "tmpl-4", "name": "Template #4",
"expiration":1418228986489, "trial":true }
]
}