@libpdf/core 0.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # LibPDF
2
+
3
+ A modern PDF library for TypeScript. Parse, modify, and generate PDFs with a clean, intuitive API.
4
+
5
+ > **Beta Software**: LibPDF is under active development. APIs may change between minor versions. Not yet recommended for production use.
6
+
7
+ ## Why LibPDF?
8
+
9
+ LibPDF was born from frustration. At [Documenso](https://documenso.com), we found ourselves wrestling with the JavaScript PDF ecosystem:
10
+
11
+ - **PDF.js** is excellent for rendering, but it's read-only
12
+ - **pdf-lib** has a great API, but chokes on slightly malformed documents
13
+ - **pdfkit** only generates, no parsing at all
14
+
15
+ We kept adding workarounds. A patch here for a malformed xref table. A hack there for an encrypted document. Eventually, we decided to build what we actually needed:
16
+
17
+ - **Lenient like PDFBox and PDF.js**: opens documents other libraries reject
18
+ - **Intuitive like pdf-lib**: clean, TypeScript-first API
19
+ - **Complete**: encryption, digital signatures, incremental saves, form filling
20
+
21
+ ## Features
22
+
23
+ | Feature | Status | Notes |
24
+ |---------|--------|-------|
25
+ | Parse any PDF | Yes | Graceful fallback for malformed documents |
26
+ | Create PDFs | Yes | From scratch or modify existing |
27
+ | Encryption | Yes | RC4, AES-128, AES-256 (R2-R6) |
28
+ | Digital Signatures | Yes | PAdES B-B, B-T, B-LT, B-LTA |
29
+ | Form Filling | Yes | Text, checkbox, radio, dropdown, signature |
30
+ | Form Flattening | Yes | Bake fields into page content |
31
+ | Merge & Split | Yes | Combine or extract pages |
32
+ | Attachments | Yes | Embed and extract files |
33
+ | Text Extraction | Yes | With position information |
34
+ | Font Embedding | Yes | TTF/OpenType with subsetting |
35
+ | Images | Yes | JPEG, PNG (with alpha) |
36
+ | Incremental Saves | Yes | Append changes, preserve signatures |
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ npm install @libpdf/core
42
+ # or
43
+ bun add @libpdf/core
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ### Parse an existing PDF
49
+
50
+ ```typescript
51
+ import { PDF } from "@libpdf/core";
52
+
53
+ const pdf = await PDF.load(bytes);
54
+ const pages = await pdf.getPages();
55
+
56
+ console.log(`${pages.length} pages`);
57
+ ```
58
+
59
+ ### Open an encrypted PDF
60
+
61
+ ```typescript
62
+ const pdf = await PDF.load(bytes, { credentials: "password" });
63
+ ```
64
+
65
+ ### Fill a form
66
+
67
+ ```typescript
68
+ const pdf = await PDF.load(bytes);
69
+ const form = await pdf.getForm();
70
+
71
+ form.fill({
72
+ name: "Jane Doe",
73
+ email: "jane@example.com",
74
+ agreed: true,
75
+ });
76
+
77
+ const filled = await pdf.save();
78
+ ```
79
+
80
+ ### Sign a document
81
+
82
+ ```typescript
83
+ import { PDF, P12Signer } from "@libpdf/core";
84
+
85
+ const pdf = await PDF.load(bytes);
86
+ const signer = await P12Signer.create(p12Bytes, "password");
87
+
88
+ const signed = await pdf.sign({
89
+ signer,
90
+ reason: "I approve this document",
91
+ });
92
+ ```
93
+
94
+ ### Merge PDFs
95
+
96
+ ```typescript
97
+ const merged = await PDF.merge([pdf1Bytes, pdf2Bytes, pdf3Bytes]);
98
+ ```
99
+
100
+ ### Draw on a page
101
+
102
+ ```typescript
103
+ import { PDF, rgb } from "@libpdf/core";
104
+
105
+ const pdf = PDF.create();
106
+ const page = pdf.addPage({ size: "letter" });
107
+
108
+ page.drawText("Hello, World!", {
109
+ x: 50,
110
+ y: 700,
111
+ fontSize: 24,
112
+ color: rgb(0, 0, 0),
113
+ });
114
+
115
+ page.drawRectangle({
116
+ x: 50,
117
+ y: 600,
118
+ width: 200,
119
+ height: 100,
120
+ color: rgb(0.9, 0.9, 0.9),
121
+ borderColor: rgb(0, 0, 0),
122
+ borderWidth: 1,
123
+ });
124
+
125
+ const output = await pdf.save();
126
+ ```
127
+
128
+ ## Runtime Support
129
+
130
+ LibPDF runs everywhere:
131
+
132
+ - **Node.js** 18+
133
+ - **Bun**
134
+ - **Browsers** (modern, with Web Crypto)
135
+
136
+ ## Philosophy
137
+
138
+ ### Be lenient
139
+
140
+ Real-world PDFs are messy. Export a document through three different tools and you'll get three slightly different interpretations of the spec. LibPDF prioritizes *opening your document* over strict compliance. When standard parsing fails, we fall back to brute-force recovery, scanning the entire file to rebuild the structure.
141
+
142
+ ### Two API layers
143
+
144
+ - **High-level**: `PDF`, `PDFPage`, `PDFForm` for common tasks
145
+ - **Low-level**: `PdfDict`, `PdfArray`, `PdfStream` for full control
146
+
147
+ ## Documentation
148
+
149
+ Full documentation at [libpdf.dev](https://libpdf.dev)
150
+
151
+ ## Sponsors
152
+
153
+ LibPDF is developed by [Documenso](https://documenso.com), the open-source DocuSign alternative.
154
+
155
+ <a href="https://documenso.com">
156
+ <img src="apps/docs/public/sponsors/documenso.png" alt="Documenso" height="24">
157
+ </a>
158
+
159
+ ## Contributing
160
+
161
+ We welcome contributions! See our [contributing guide](CONTRIBUTING.md) for details.
162
+
163
+ ```bash
164
+ # Clone the repo
165
+ git clone https://github.com/libpdf/core.git
166
+ cd libpdf
167
+
168
+ # Install dependencies
169
+ bun install
170
+
171
+ # Run tests
172
+ bun run test
173
+
174
+ # Type check
175
+ bun run typecheck
176
+ ```
177
+
178
+ ## License
179
+
180
+ [MIT](LICENSE)
181
+
182
+ The `src/fontbox/` directory is licensed under [Apache-2.0](src/fontbox/LICENSE) as it is derived from [Apache PDFBox](https://pdfbox.apache.org/).
183
+
184
+