Skip to content

pdf-lib

Create, modify, merge, split, and fill PDF documents in the browser. Zero server dependencies.

Not yet verified
Report issueDemo online
MIT★ 8000

Open the official app on pdf-lib.js.org

This tool is hosted by its maintainers. Click below to open pdf-lib.js.org in a new tab — it's their official demo.

Browse pdf & tools tools →

What's next with pdf-lib?

Choose how you want to get started.

Use it free

Open the official tool or demo — no account needed.

Free

Self-host it

Run the open-source version on your own infrastructure.

Open

What is pdf-lib?

pdf-lib is an open-source JavaScript library for programmatically creating and modifying PDF documents. Developed under the MIT license, it enables developers to generate new PDFs or alter existing ones without requiring native dependencies. The tool is widely used by web developers, data analysts, and automation engineers who need to manipulate PDFs in environments like browsers, Node.js, or Deno. It addresses the challenge of working with PDFs in JavaScript by providing a pure-JavaScript API that supports text rendering, page operations, and basic document structure editing. By eliminating the need for external libraries or server-side processing, pdf-lib streamlines workflows for tasks such as generating reports, editing forms, or integrating PDFs into larger applications.

How it works

pdf-lib is a TypeScript-based library compiled to JavaScript, designed for creating and modifying PDFs in any JavaScript runtime. It provides a low-level API to construct documents from scratch or alter existing files by manipulating pages, text, and embedded resources. The primary purpose of pdf-lib is to enable developers to handle PDFs without relying on native system tools or third-party libraries. It supports tasks like adding text, embedding fonts, and integrating pages from other PDFs, making it suitable for both simple and complex document manipulation. pdf-lib allows users to create PDFs by initializing a document, adding pages, and rendering text or graphics. For example, developers can generate a new PDF with a single page containing custom text using `pdfDoc.addPage()` and `page.drawText()`. It also supports modifying existing PDFs by loading them, accessing individual pages, and applying changes such as redacting text or inserting new content.

How to use it

  1. 1Import the library: `import { PDFDocument } from 'pdf-lib'`.
  2. 2Create a new document: `const pdfDoc = await PDFDocument.create()`.
  3. 3Add a page and render content: `const page = pdfDoc.addPage(); page.drawText('Example text')`.
  4. 4Save the output: `const pdfBytes = await pdfDoc.save()`. For modification, load an existing PDF: `const pdfDoc = await PDFDocument.load(pdfBytes)`, then edit pages before saving. Practical tips include using `async/await` for file operations, ensuring fonts are embedded correctly, and verifying page dimensions when adding content. Developers should also handle errors during PDF loading, as corrupted files may cause exceptions.

What it can do

  • Generation
  • PDF Processing

Use cases

Assumptions and limitations

Assumptions

  • source: https://github.com/Hopding/pdf-lib
  • license: MIT — free to use
  • privacy: Opens an external demo

Limitations

  • Limited support for advanced PDF features like form fields or digital signatures
  • No built-in GUI for non-technical users; requires programming knowledge
  • Font embedding may require manual configuration for certain typefaces
  • Performance may degrade with very large or complex PDFs
  • Does not handle PDF encryption or password protection

Understanding the result

Create, modify, merge, split, and fill PDF documents in the browser. Zero server dependencies.

Tool details

  • Clearly flagged when a network request is needed.
  • No account, no sign-up, and no tracking of your content.
  • Powered by pdf-lib (MIT).
Built with
pdf-lib (Hopding/pdf-lib)
License
MIT
Runs locally
No — requires a network request
Verification
Not yet verified
Input
PDF
Output
PDF, Generated Output
Open-source source & license

Built with Hopding/pdf-lib. OpenToolVault provides the discovery and browser interface while crediting the original project maintainers.

Built with
pdf-lib
License
MIT
View source on GitHub

Open-source project

OpenToolVault is an independent directory. We are not affiliated with or endorsed by this project.

References

Frequently asked

How do I create a PDF with pdf-lib?

To create a PDF, import the library, initialize a new document, add pages, and render content. For example: `import { PDFDocument } from 'pdf-lib'; const pdfDoc = await PDFDocument.create(); const page = pdfDoc.addPage(); page.drawText('Hello, World!'); const pdfBytes = await pdfDoc.save();` This generates a basic PDF with a single page containing the text.

How does pdf-lib handle existing PDFs?

pdf-lib loads existing PDFs using the `PDFDocument.load()` method, which parses the file's structure. It then allows developers to access individual pages, modify their content, and save the updated document. This process works for most standard PDFs but may fail with heavily encrypted or corrupted files.

How do I add an image to a PDF?

To add an image, first load it as a Uint8Array using `fetch()` or `Blob`, then use `page.drawImage()` with the image data. Example: `const imageBytes = await fetch('image.png').then(res => res.arrayBuffer()); const image = await pdfDoc.embedImage(imageBytes); page.drawImage(image, { x: 50, y: 50, width: 100, height: 100 });`

How does pdf-lib compare to iText or PDFKit?

pdf-lib is a pure-JavaScript library with no native dependencies, making it compatible with browsers and Node.js environments. In contrast, iText requires Java or a commercial license for advanced features, while PDFKit is a Ruby gem. pdf-lib offers more flexibility for JavaScript developers but lacks some enterprise-grade features found in alternatives.

What should I do if PDF loading fails?

If loading a PDF fails, check for corrupted files or unsupported features like encryption. Ensure the input is a valid PDF byte array. If the error mentions 'invalid PDF', verify the source file's integrity. For large files, increase memory limits in your environment or split the document into smaller parts.

Spotted something wrong with pdf-lib, or want to maintain it? See how to help.