Code Monkey home page Code Monkey logo

pdf-generator's Introduction

Template pdf generator

This is a small nodejs-script that generates a pdf-file, given some data and a twig template. It uses wkhtmltopdf through the wkhtmltopdf node package. wkhtmltopdf has to be installed.

Installation

npm install template-pdf-generator

Usage

var pdfGenerator = require('template-pdf-generator');
var fs = require('fs');

var data = {
  name: 'World'
};

var template = '<h1>Hello {{name}}</h1>';

var css = 'h1 {color: red}';

pdfGenerator(data, template, css).pipe(fs.createWriteStream('out.pdf'));

You can also use some options:

pdfGenerator(data, template, css, options)

The options object is the same as documented in the wkhtmltopdf node package.

Usage as a command line tool

Clone or download the project.

From the directory of the project run:

node index.js -data data.json -template template.html

Options :

  • -data or -D (mandatory) : path and name of the json data file
  • -template or -T (mandatory) : path and name of the template file
  • -css : path and name of the css file, if necessary
  • -out : path and name of the resulting pdf file. By default, the created file is out.pdf in the script root directory.

Further work

  • Allow other template engines than twig
  • Allow other encoding than utf-8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.