{"id":18812536,"url":"https://github.com/jsreport/toner","last_synced_at":"2025-04-13T21:24:15.867Z","repository":{"id":32771213,"uuid":"36362787","full_name":"jsreport/toner","owner":"jsreport","description":"node library for dynamic assembling documents and printing them into various formats","archived":false,"fork":false,"pushed_at":"2016-03-22T09:30:00.000Z","size":19,"stargazers_count":8,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T11:43:35.002Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jsreport.net","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsreport.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-27T11:35:47.000Z","updated_at":"2022-01-18T02:34:58.000Z","dependencies_parsed_at":"2022-07-12T16:09:48.623Z","dependency_job_id":null,"html_url":"https://github.com/jsreport/toner","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsreport%2Ftoner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsreport%2Ftoner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsreport%2Ftoner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsreport%2Ftoner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsreport","download_url":"https://codeload.github.com/jsreport/toner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317688,"owners_count":21083521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:34:03.439Z","updated_at":"2025-04-13T21:24:15.841Z","avatar_url":"https://github.com/jsreport.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#jsreport toner\n[![Build Status](https://travis-ci.org/jsreport/toner.png?branch=master)](https://travis-ci.org/jsreport/toner)\n\n\n##Deprecation note\nThis package is not being developed anymore. We recommend to use [jsreport-core](https://github.com/jsreport/jsreport-core) instead. It has almost the same API but with many more recipes, extensions and recipes.\n\n##jsreport toner\n**[node](https://nodejs.org/) library for dynamic assembling documents and printing them into various formats** \n(written for [jsreport](http://jsreport.net))\n\n\n```js\nvar toner = require(\"toner\")();\ntoner.engine(\"jsrender\", require(\"toner-jsrender\"));\ntoner.recipe(\"wkhtmltopdf\", require(\"toner-wkhtmltopdf\")());\n\ntoner.render({\n    template: { \n\t    engine: \"jsrender\",\n\t\trecipe: \"wkhtmltopdf\", \n\t\tcontent: \"\u003ch1\u003e{{:foo}}\u003c/h1\u003e\"\n\t},\n    data: { foo: \"hello world\"}\n}, function(err, res) {\n    var pdfbuffer = res.content;\n    var pdfstream = res.stream;    \n});\n```\n\n##Basics\n\n###Engines\nDocuments are assembled using javascript templating engines. The **engine** needs to be first registered in toner.\n\n```js\ntoner.engine(\"[engine name]\", pathToEngineScript);\n```\n\nYou can write your own engine or use an existing one:\n\n- [toner-handlebars](https://github.com/jsreport/toner-handlebars)\n- [toner-jsrender](https://github.com/jsreport/toner-jsrender)\n\nNote that templating engine runs safely in another sand-boxed process. You don't have to be afraid to run user defined templates. See [script-manager](https://github.com/pofider/node-script-manager) for details.\n\nYou can register and use `none` engine to skip its processing:\n\n```js\ntoner.engine('none', toner.noneEngine);\ntoner.render({\n  template: {\n    engine: 'none'   \n    ...\n  }\n```\n\n###Recipes\nThe actual printing of the document into pdf, excel or any other type of the document is done by something we call **recipe**. The recipe also needs to be registered first.\n\n```js\ntoner.recipe(\"[recipe name]\", function(req, res) { ... });\n```\n\nYou can also write your own recipe or use an existing one:\n\n- [toner-phantom](https://github.com/jsreport/toner-phantom)\n- [toner-html-to-xlsx](https://github.com/jsreport/toner-html-to-xlsx)\n- [toner-wkhtmltopdf](https://github.com/jsreport/toner-wkhtmltopdf)\n\nYou can use `html` recipe to simply produce html:\n\n```js\ntoner.recipe(\"html\", toner.htmlRecipe);\ntoner.render({\n  template: {\n    recipe: 'html'   \n    ...\n  }\n```\n\n###Render\nThe complete document generation is invoked using `toner.render` function:\n```js\ntoner.render({\n    template: { \n\t    engine: \"jsrender\",\n\t\trecipe: \"wkhtmltopdf\", \n\t\tcontent: \"\u003ch1\u003e{{:foo}}\u003c/h1\u003e\"\n\t},\n    data: { foo: \"hello world\"}\n}, function(err, res) {\n    var pdfbuffer = res.content;\n    var pdfstream = res.stream;    \n});\n```\nThe only parameter is an object representing rendering request. The request has following structure:\n```js\n{\n\t//[required]\n    template: { \n\t    //[required] templating engine used to assemble document\n\t    engine: \"jsrender\",\n\t    //[required] recipe used for printing previously assembled document\n\t\trecipe: \"wkhtmltopdf\", \n\t\t//[required] template for the engine\t\t\n\t\tcontent: \"\u003ch1\u003e{{:foo}}\u003c/h1\u003e\",\n\t\t//javascript helper functions used by templating engines\n\t\thelpers: \"function foo() { ...}\" + \n\t\t\t\t \"function foo2() { ... }\"\n\t\t//any other settings used by recipes\t\t \n\t\t...\t\t \n\t},\n\t//dynamic data inputs used by templating engines\n    data: { foo: \"hello world\"}\n    ...\n}\n```\n\nThe render callback then contains the response with\n```js\n{\n\t//node.js buffer with the document\n\tcontent: ...\n\t//stream with the document\n\tstream: ...\n\t//http response headers with valid content type..\n\theaders: { ... }\n}\n```\n\n##Pipe the document to the http response\n```js\nvar http = require('http');\nhttp.createServer(function (req, res) {\n    toner.render({...}, function(err, out) {\n        out.stream.pipe(res);\n    });\n}).listen(1337, '127.0.0.1');\n```\n\n##Hooks\nIt is expected there will soon popup other packages hooking into the Toner and adding additional functionality. For this case Toner provides several hooks which can be used to extend it.\n\n```js\ntoner.before(function(req, res, cb) { ... });\ntoner.after(function(req, res, cb) { ... });\ntoner.afterEngine(function(req, res, cb) { ... });\n``` \n\n##Options\nCalling Toner accepts some options as the parameter\n```js\nvar toner = require(\"toner\")({ ... });\n```\n\nPossible options:\n- `tempDirectory` - this attribute is used by the recipes to store temporary files\n- options passed to the [script-manager](https://github.com/pofider/node-script-manager) depndency\n\n\n##Tests\n\n```bash\nnpm install\nnpm test\n```\n\n##Contributions\nYes, please.\n\n##License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsreport%2Ftoner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsreport%2Ftoner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsreport%2Ftoner/lists"}