
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
A lightweight and easy-to-use package for generating PDF files from HTML content without the use of external dependencies.
H2PDF is a Node.js package that allows you to easily convert HTML to PDF in your Express.js applications. It uses a custom-built PDF generation engine and does not rely on Puppeteer or any other third-party PDF generation tools.
You can install H2PDF using npm:
npm install h2pdf
Using H2PDF is very simple. Here's an example of how you can use it in your Express.js app:
const express = require('express');
const app = express();
const h2pdf = require('h2pdf');
app.get('/pdf', async (req, res) => {
const html = '<h1>Hello, World!</h1>';
const pdf = await h2pdf(html);
res.contentType('application/pdf');
res.send(pdf);
});
app.listen(3000, () => console.log('Server started on port 3000'));
In this example, we define a route that generates a PDF file from an HTML string and sends it as a response to the client.
H2PDF exports a single function with the following signature:
async function h2pdf(html: string, options: object = {}): Promise<Buffer>
The html
parameter is the HTML string that you want to convert to a PDF.
The options
parameter is an optional object that allows you to customize the PDF generation process. Here are the available options:
pageSize
: A string or object that specifies the size of the PDF page. You can use any of the predefined page sizes (e.g. 'A4', 'Letter', etc.) or define your own custom size using an object with width and height properties (in millimeters).
pageOrientation
: A string that specifies the orientation of the PDF page ('portrait' or 'landscape').
marginTop
, marginBottom
, marginLeft
, marginRight
: Numbers that specify the size of the margins (in millimeters).
headerTemplate
, footerTemplate
: Strings that specify the content of the header and footer sections of the PDF.
displayHeaderFooter
: A boolean that specifies whether to display the header and footer sections of the PDF.
printBackground
: A boolean that specifies whether to print the background colors and images of the HTML.
scale
: A number that specifies the scaling factor for the PDF.
H2PDF is licensed under the MIT License.
FAQs
A lightweight and easy-to-use package for generating PDF files from HTML content without the use of external dependencies.
The npm package h2pdf receives a total of 1 weekly downloads. As such, h2pdf popularity was classified as not popular.
We found that h2pdf 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
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.