You can use the UMD Module as mentioned in their GitHub page. Here are some of the useful information I extracted from their GitHub page.
UMD Module
You can also download pdf-lib as a UMD module from unpkg or jsDelivr. The UMD builds have been compiled to ES5, so they should work in any modern browser. UMD builds are useful if you aren't using a package manager or module bundler. For example, you can use them directly in the tag of an HTML page.
The following builds are available:
- https://unpkg.com/pdf-lib/dist/pdf-lib.js
- https://unpkg.com/pdf-lib/dist/pdf-lib.min.js
- https://cdn.jsdelivr.net/npm/pdf-lib/dist/pdf-lib.js
- https://cdn.jsdelivr.net/npm/pdf-lib/dist/pdf-lib.min.js
NOTE: if you are using the CDN scripts in production, you should include a specific version number in the URL, for example:
- https://unpkg.com/[email protected]/dist/pdf-lib.min.js
- https://cdn.jsdelivr.net/npm/[email protected]/dist/pdf-lib.min.js
Example:
<html>
<head>
<meta charset="utf-8" />
<script src="https://unpkg.com/pdf-lib"></script>
</head>
<body>
<div style="display: flex; width: 100%; height: 100%; flex-direction: column; overflow: hidden;">
<iframe id="pdf" style="flex-grow: 1; border: none; margin: 0; padding: 0;"></iframe>
</div>
</body>
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/pdf-lib.min.js"></script>
<script>
createPdf();
async function createPdf() {
const pdfDoc = await PDFLib.PDFDocument.create();
const page = pdfDoc.addPage([350, 400]);
page.moveTo(110, 200);
page.drawText('Hello World!');
const pdfDataUri = await pdfDoc.saveAsBase64({ dataUri: true
});
document.getElementById('pdf').src = pdfDataUri;
}
</script>
</html>
Answer from Lakshitha Kanchana on Stack OverflowPDF-LIB
pdf-lib.js.org
PDF-LIB · Create and modify PDF documents in any JavaScript environment.
import { degrees, PDFDocument, rgb, StandardFonts } from 'pdf-lib'; async function modifyPdf() { const url = 'https://pdf-lib.js.org/assets/with_update_sections.pdf' const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer()) const pdfDoc = await PDFDocument.load(existingPdfBytes) const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica) const pages = pdfDoc.getPages() const firstPage = pages[0] const { width, height } = firstPage.getSize() firstPage.drawText('This text was added with JavaScript!', { x: 5, y: height / 2 + 300, size: 50, font: helveticaFont, color: rgb(0.95, 0.1, 0.1), rotate: degrees(-45), }) const pdfBytes = await pdfDoc.save() }
GitHub
github.com › Hopding › pdf-lib
GitHub - Hopding/pdf-lib: Create and modify PDF documents in any JavaScript environment
How to use pdf-lib in AWS Lambdas - a tutorial written by Crespo Wang · Working With PDFs in Node.js Using pdf-lib - a tutorial by Valeri Karpov
Starred by 8.1K users
Forked by 828 users
Languages TypeScript 80.9% | HTML 9.9% | JavaScript 8.5% | Objective-C 0.3% | CSS 0.2% | Starlark 0.1% | Java 0.1%
Videos
14:59
Using PDF-lib and Node.js to populate PDF form - YouTube
29:25
Javascript PDF.js & PDF-LIB Project to Delete Specific Pages inside ...
18:07
Node.js PDF-LIB Example to Create PDF File and Add Text ...
03:28
✨ Generate PDFs Dynamically in Node.js with PDF-Lib 📄 Full ...
07:35
Build a PDF-LIB PDF Editor to Highlight,Redact and Annotate ...
19:23
Javascript PDF-LIB Tutorial to Add Page Numbers to All Pages of ...
How can I build a PDF editor using JavaScript?
You can build a PDF editor using JavaScript by leveraging libraries like PDF-lib, PSPDFKit, or PDF.js. These libraries provide APIs to create, modify, and interact with PDF documents.
pspdfkit.com
pspdfkit.com › blog › 2021 › how-to-build-a-javascript-pdf-editor
JavaScript PDF editor tutorial using pdf‑lib
Can I add annotations to PDFs using a JavaScript PDF editor?
Yes, most PDF libraries support adding annotations such as highlights, comments, and shapes. You can use the library's API to create and manipulate these annotations.
pspdfkit.com
pspdfkit.com › blog › 2021 › how-to-build-a-javascript-pdf-editor
JavaScript PDF editor tutorial using pdf‑lib
What are the benefits of using a JavaScript-based PDF editor?
A JavaScript-based PDF editor allows for client-side processing, reducing the need for server resources. It also provides a seamless user experience by enabling PDF editing directly within the browser.
pspdfkit.com
pspdfkit.com › blog › 2021 › how-to-build-a-javascript-pdf-editor
JavaScript PDF editor tutorial using pdf‑lib
npm
npmjs.com › package › pdf-lib
pdf-lib - npm
How to use pdf-lib in AWS Lambdas - a tutorial written by Crespo Wang · Working With PDFs in Node.js Using pdf-lib - a tutorial by Valeri Karpov
» npm install pdf-lib
Published Nov 06, 2021
Version 1.17.1
Author Andrew Dillon
Repository https://github.com/Hopding/pdf-lib
Homepage https://pdf-lib.js.org/
Mozilla
mozilla.github.io › pdf.js › examples
PDF.js - Examples
This tutorial shows how PDF.js can be used as a library in a web browser.
Nutrient
nutrient.io › blog › sdk › complete guide to pdfjs
Complete guide to PDF.js
August 11, 2025 - PDF.js is Mozilla’s open source JavaScript library for rendering PDFs in browsers without plugins. This guide covers PDF.js setup, rendering with the Canvas API, navigation controls, zoom functionality, and handling basic annotations. However, for enterprise applications requiring advanced features, high performance, and dedicated support, Nutrient Web SDK is the ideal solution.
The Code Barbarian
thecodebarbarian.com › working-with-pdfs-in-node-js.html
Working With PDFs in Node.js Using pdf-lib | www.thecodebarbarian.com
const { PDFDocument } = require('pdf-lib'); const fs = require('fs'); run().catch(err => console.log(err)); async function run() { // Create a new document and add a new page const doc = await PDFDocument.create(); const page = doc.addPage(); // Load the image and store it as a Node.js buffer in memory let img = fs.readFileSync('./logo.png'); img = await doc.embedPng(img); // Draw the image on the center of the page const { width, height } = img.scale(1); page.drawImage(img, { x: page.getWidth() / 2 - width / 2, y: page.getHeight() / 2 - height / 2 }); // Write the PDF to a file fs.writeFileSync('./test.pdf', await doc.save()); }
ComPDF
compdf.com › blog › build-a-javascript-pdf-editor-with-pdf-lib
How to Build a JavaScript PDF Editor with pdf-lib 2024
How to create a JavaScript PDF editor/reader using ComPDFKit PDF-lib? In this tutorial, we will offer a step-by-step guide. Enhance your project efficiently.
Mozilla
mozilla.github.io › pdf.js › getting_started
PDF.js - Getting Started
An introduction to PDF.js with examples.
GitHub
github.com › rivy › js.pdf-lib
GitHub - rivy/js.pdf-lib: Create and modify PDF documents in any JavaScript environment
See below for detailed installation instructions on installing @pdf-lib/fontkit as a UMD or NPM module. This example produces this PDF (when this font is used for the fontBytes variable).
Author rivy
CodeSandbox
codesandbox.io › examples › package › pdf-lib
pdf-lib examples - CodeSandbox
Use this online pdf-lib playground to view and fork pdf-lib example apps and templates on CodeSandbox.
PDF-LIB
pdf-lib.js.org › docs › api
pdf-lib · PDF-LIB
pdf-lib · BlendMode · ColorTypes · Duplex · ImageAlignment · LineCapStyle · LineJoinStyle · NonFullScreenPageMode · ParseSpeeds · PrintScaling · ReadingDirection · RotationTypes · StandardFonts · TextAlignment · TextRenderingMode · PDFButton · PDFCheckBox ·
JSFiddle
jsfiddle.net › Hopding › 64zajhge › 1
Modify Document (pdf-lib) - JSFiddle - Code Playground
The Code Completion will now also have the context of all panels before suggesting code to you - so if for example you have some CSS or JS, the HTML panel will suggest code based on the other two panels.
HayaGeek
hayageek.com › home › pdf-lib tutorial – generate pdf in node.js
Pdf-lib tutorial - Generate PDF in Node.js
November 29, 2023 - Welcome to this in-depth tutorial on the npm package pdf-lib. This package is a powerful tool for creating and modifying PDF documents in JavaScript. Throughout this guide, we’ll cover a wide range of examples, showcasing how to harness the features of pdf-lib to achieve various tasks.