# pdf-lib — Create and Modify PDFs in Any JavaScript Environment > A pure JavaScript library for creating new PDFs and modifying existing ones in Node.js, browsers, and edge runtimes. ## Install Save as a script file and run: # pdf-lib — Create and Modify PDFs in Any JavaScript Environment ## Quick Use ```bash npm install pdf-lib ``` ```js import { PDFDocument } from 'pdf-lib'; const pdfDoc = await PDFDocument.create(); const page = pdfDoc.addPage([600, 400]); page.drawText('Hello from pdf-lib!', { x: 50, y: 350, size: 30 }); const pdfBytes = await pdfDoc.save(); // pdfBytes is a Uint8Array of the finished PDF ``` ## Introduction pdf-lib is a pure JavaScript library that can both create new PDF documents and modify existing ones. Unlike many PDF tools that only support generation, pdf-lib can load a PDF, add pages, fill form fields, embed images, and merge documents. It runs everywhere JavaScript runs: Node.js, browsers, Deno, React Native, and edge runtimes, with zero native dependencies. ## What pdf-lib Does - Creates new multi-page PDF documents from scratch - Loads and modifies existing PDF files (add text, images, pages) - Fills and reads PDF form fields (AcroForms) - Merges pages from multiple PDF documents into one - Embeds fonts, PNG images, and JPEG images ## Architecture Overview pdf-lib parses PDF files into an in-memory object model representing the PDF's cross-reference table, object streams, and page tree. Modifications are applied to this model, and the library serializes it back into valid PDF bytes. Because it is written in pure TypeScript with no native bindings, it works identically across all JavaScript runtimes. Font embedding uses a built-in subset of standard fonts, with support for custom TrueType font embedding. ## Self-Hosting & Configuration - Install via npm: `npm install pdf-lib` - For custom fonts, also install `@pdf-lib/fontkit`: `npm install @pdf-lib/fontkit` - Load an existing PDF: `const pdfDoc = await PDFDocument.load(existingPdfBytes)` - Embed custom fonts: `pdfDoc.registerFontkit(fontkit); const font = await pdfDoc.embedFont(fontBytes)` - Works directly in browser `