Get started with pdf-lib CDN
MIT licensed
PDF-lib: Powerful, flexible Node.js library for handling PDF files.
Tags:- pdf-lib
- document
- create
- modify
- creation
- modification
- edit
- editing
- typescript
- javascript
- library
Stable version
Copied!
How to start using pdf-lib CDN
const PDFDocument = require("pdf-lib"); // Import the PDF-Lib library
async function createPDF() {
const pdfDoc = await PDFDocument.load(""); // Create a new empty PDF document
// Add a new page
const page = pdfDoc.addPage();
// Add some text content
page.drawText("Hello, World!", { align: "center" });
// Save the PDF in the browser
const pdfBytes = await pdfDoc.save();
const blob = new Blob([pdfBytes], { type: "application/pdf" });
// Create a URL for the download
const url = URL.createObjectURL(blob);
// Create an anchor element and click it to download the PDF
const link = document.createElement("a");
link.href = url;
link.download = "hello_world.pdf";
document.body.appendChild(link);
link.click();
// Clean up
URL.revokeObjectURL(url);
}
createPDF();
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!