Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
@isneezy/pdf-generator
Advanced tools
A powerful and versatile library for converting HTML pages, templates, and URLs into high-quality PDF documents
@isneezy/pdf-generator
@isneezy/pdf-generator
is a powerful and versatile library that allows you to convert HTML pages, templates, and URLs
into high-quality PDF documents using Chromium and Puppeteer.
With @isneezy/pdf-generator, you can easily create PDFs with support for table of contents and various page configurations such as page size, margins, and more. The library is designed to be easy to use and integrate into your existing projects, making it the perfect solution for developers looking to add PDF functionality to their applications.
To install the package, you can use npm or yarn.
npm install @isneezy/pdf-generator
yarn add @isneezy/pdf-generator
The package exports a single class PdfGenerator
that you can use to create a new instance of the library
import PdfGenerator from '@isneezy/pdf-generator'
const instance = PdfGenerator.instance()
The class has the following methods:
This method generates a PDF from the provided options and returns a promise that resolves to a buffer with the PDF content.
The options object has the following shape:
Option | Type | Description |
---|---|---|
goto | string | URL to the HTML content/handlebars template to be converted to PDF. If provided, it takes priority over the template option. |
template | string | HTML content/Handlebars template to be converted to PDF. If a goto option is provided, this option will be ignored. |
context | object | The data that will be passed to the handlebars template for rendering. |
headerTemplate | string | Handlebars template to be rendered as the page header |
footerTemplate | string | Handlebars template to be rendered as the page footer. If a footer template is provided in the document, this option will take priority. |
format | string | Sets the paper format to be used when printing a PDF. Accepted values include: letter, legal, tabloid, ledger, a0, a1, a2, a3, a4, a5, a6. |
landscape | boolean | If set to true, the PDF will be generated in landscape orientation, otherwise it will be generated in portrait orientation. |
margin | object | An object with the properties top, bottom, left, right which sets the page margins. The values should be strings with units, e.g. "10mm". |
This method releases the resources used by the instance of the PdfGenerator
class, it should be called after using the generate method.
instance.close()
Here is an example of how to use the library to generate a PDF from a handlebars template and context data:
import { writeFileSync } from 'fs'
import PdfGenerator from '@isneezy/pdf-generator'
const template = '<p>Hello from {{ name }}</p>'
const context = { name: 'PDF Generator' }
// Creates a new instance of PdfGenerator
const instance = PdfGenerator.instance()
// generate the PDF file
instance.generate({ template, context })
.then(buffer => {
// write the file to disk
writeFileSync('path/to/the/output.pdf', buffer)
})
.finally(instance.close)
FAQs
A powerful and versatile library for converting HTML pages, templates, and URLs into high-quality PDF documents
The npm package @isneezy/pdf-generator receives a total of 2 weekly downloads. As such, @isneezy/pdf-generator popularity was classified as not popular.
We found that @isneezy/pdf-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.