GithubHelp home page GithubHelp logo

sails-hook-pdf's Introduction

sails-hook-pdf

Dependency Status

Pdf hook for Sails JS, using html-pdf

Installation

npm i --save sails-hook-pdf

Usage

sails.hooks.pdf.make(template, data, options, cb)

Parameter Type Details
template string Relative path from templateDir (see "Configuration" below) to a folder containing pdf templates.
data object Data to use to replace template tokens
options object Pdf options (right now just output)
cb function Callback to be run after the pdf is created (or if an error occurs). It will contain the path to the file.

Configuration

By default, configuration lives in sails.config.pdf. The configuration key (pdf) can be changed by setting sails.config.hooks['sails-hook-pdf'].configKey.

Parameter Type Details
templateDir string Path to view templates relative to sails.config.appPath (defaults to views/pdfTemplates)

Templates

Templates are generated using your configured Sails View Engine, allowing for multiple template engines and layouts. If Sails Views are disabled, will fallback to EJS templates. To define a new email template, create a new folder with the template name inside your templateDir directory, and add an pdf.ejs file inside the folder (substituting .ejs for your template engine).

Example

Given the following pdf.ejs file contained in the folder views/pdfTemplates/testPdf:

<!DOCTYPE HTML>
<html>
  <head>
    <title>TEST</title>
  </head>
  <body>
    <div>
      <p>Hello <%=a%>!</p>
    </div>
  </body>
</html>

In your app you would run the following command.

sails.hooks.pdf.make(
  "testPdf",
  {
    a: "Bob Dole",
  },
  {
    output: 'assets/pdfs/mypdf.pdf'
  },
  function(err, result) {
    console.log(err, result);
  }
);

Or

sails.hooks.pdf.make("testPdf",
{
  a: "Bob Dole",
},
{
  output: 'assets/pdfs/mypdf.pdf'
}).then(function(result) {
  console.log(result);
}).catch(function(error) {
  console.log(error);
});

will result in creating the pdf.

sails-hook-pdf's People

Contributors

surgery18 avatar

Stargazers

 avatar Amnash Anwar avatar Felipe Ruiz avatar Mike McNeil avatar

Watchers

 avatar

Forkers

wimarbueno

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.