
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
pdf-lib-draw-table-beta
Advanced tools
Table of Contents
npm install pdf-lib-draw-table-beta
If you don't already have pdf-lib then
npm install pdf-lib pdf-lib-draw-table
This is a very simple example (server side as we are using fs). Exactly the same code (minus fs!) will also work client side for example in a react component. The options are fairly extensive for formatting and styling, we just show a couple here. You can also pass us a JSON table if you prefer, either that or array as below is fine. Either can contain any of the following within each cell: string - As in the example below. This is drawn as wrapped text, no word splitting. Image, Link, CustomSyledText OR AN ARRAY OF ANY COMBO OF THE ABOVE If you provide an array we automatically put each item on its own line, as such if you need to manually new line text, this is a way of doing that.
import { PDFDocument } from 'pdf-lib';
import { drawTable } from 'pdf-lib-draw-table';
import fs from 'fs';
(async () => {
// Create a new PDFDocument
const pdfDoc = await PDFDocument.create();
// Add a new page
const page = pdfDoc.addPage([600, 800]);
// Define the table data
const tableData = [
['Name', 'Age', 'City'],
['Alice', '24', 'New York'],
['Bob', '30', 'San Francisco'],
['Charlie', '22', 'Los Angeles'],
];
// Set the starting X and Y coordinates for the table
const startX = 50;
const startY = 750;
// Set the table options
const options = {
header: {
hasHeaderRow: true,
backgroundColor: rgb(0.9, 0.9, 0.9),
},
};
try {
// Draw the table
const tableDimensions = await drawTable(pdfDoc, page, tableData, startX, startY, options);
console.log('Table dimensions:', tableDimensions);
// Serialize the PDF to bytes and write to a file
const pdfBytes = await pdfDoc.save();
fs.writeFileSync('table-example.pdf', pdfBytes);
} catch (error) {
console.error('Error drawing table:', error);
}
})();
Massive thanks to PDF lib for creating a powerful PDF manipulation library.
Also, big thanks to Typedoc for providing the amazing documentation generator tool that makes /docs: https://github.com/TypeStrong/typedoc
FAQs
A library for drawing tables in PDFs using pdf-lib.
The npm package pdf-lib-draw-table-beta receives a total of 142 weekly downloads. As such, pdf-lib-draw-table-beta popularity was classified as not popular.
We found that pdf-lib-draw-table-beta 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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.