You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dynamic-html-to-pdf

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-html-to-pdf

Create dynamic PDF from Edge.js template

0.1.9
latest
Source
npmnpm
Version published
Maintainers
0
Created
Source

dynamic-html-to-pdf

What is dynamic-html-to-pdf ?

dynamic-html-to-pdf is a small package used to create pdf from edge template.

Edge transform edge template into html string.

Playwright transform html string into pdf file.

Installation

npm install dynamic-html-to-pdf --save

How to use dynamic-html-to-pdf

const pdf = require('dynamic-html-to-pdf')

const template = '/absolute/path/to/file/template.edge'

// Context that can be used inside the views
const context = { users: [{ name: 'John Doe' }, { name: 'Jane Doe' }] }

// Playwright options (https://playwright.dev/docs/api/class-page#page-pdf)
const options = { path: './output.pdf' }

// Folder that contain views (https://edgejs.dev/docs/getting_started#mounting-disks)
const defaultDisk = '/absolute/path/to/file/'

// Function that can be used inside the views (https://edgejs.dev/docs/templates_state#globals)
const globals = { toLowerCase: (string) => string.toLowerCase() }

pdf.create(template, context, options, defaultDisk, globals)

Look https://playwright.dev/docs/api/class-page#page-pdf for different options.

Create template.edge

<html>

<head>
  <style>
    .page {
      position: relative;
      width: 100%;
      height: 100%;
    }
  </style>
</head>

<body>
  @each(user in users)
    <div class="page">
      {{ toLowerCase(user.name) }}
    </div>
  @endeach
</body>

</html>

Look https://edgejs.dev/docs/introduction for edge syntax

FAQs

Package last updated on 04 Dec 2024

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