Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sails-html-pdf

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails-html-pdf

Convert ejs template to pdf with Sails.js

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

sails-html-pdf

HTML to PDF hook for Sails JS

Installation

npm i --save sails-html-pdf

Usage

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

ParameterTypeDetails
templatestringRelative path from templateDir (see "Configuration" below) to a folder containing pdf templates.
dataobjectData to use to replace template tokens
optionsobjectPdf options (right now just output)
cbfunctionCallback 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.

ParameterTypeDetails
templateDirstringPath 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.

Keywords

FAQs

Package last updated on 09 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc