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

pdfactory-core

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfactory-core

- Generate pdf documents from html files. - Generate dynamic pdf documents using ejs files as templates.

  • 0.0.45
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

pdfactory-core

  • Generate pdf documents from html files.
  • Generate dynamic pdf documents using ejs files as templates.

Supports

  • html
  • ejs

Installation

yarn add pdfactory-code

Example using ejs and express

Directory structure

/main.js
/templates
  /partials
    /page1.ejs
  /document.ejs

document.ejs

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
</head>

<body>
  <div>
  <%- include('./partials/page1.ejs'); -%>
  </div>
</body>

</html>

page1.ejs

<div>
  <%= title %>
</div>

main.js

const express = require("express");
const path = require("path");
const { pdfactory } = require("pdfactory-core");

const templatesDir = path.join(__dirname, "templates");
const partialsDir = path.join(__dirname, "templates", "partials");

const DEFAULT_CONFIG = {
  templatesDir: [templatesDir, partialsDir],
  ejsOptions: {
    views: [templatesDir], // For relative include paths  
  },
};

const init = async () => {
  const pdfactoryHandler = await pdfactory(DEFAULT_CONFIG);

  const app = express();

  app.use(express.json());

  const requestHandler = async (req, res) => {
    let pdf = null;

     try {
      pdf = await pdfactoryHandler(req.body)
    } catch (e) {
      res.status(400).send(e)
      return
    }
    
    res.set({
      "Content-Type": "application/pdf",
      "Content-Length": pdf.length,
    });

    res.send(pdf);
  };

  app.post("/", requestHandler);

  app.listen(3000);

  return app;
};

init();

Example request

POST https://localhost:3000
{
    "document": "document",
    "data": {
        "title": "pdfactory pdf"
    }
}

Keywords

FAQs

Package last updated on 27 Apr 2023

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