@peculiar/pdf-core 1.17.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/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # `@peculiar/pdf-core`
2
+
3
+ A powerful and flexible TypeScript library for PDF document manipulation, supporting both creation and modification of PDF files. The library provides comprehensive functionality for working with PDF objects, incremental updates, cross-reference tables, and encryption.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @peculiar/pdf-core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Creating a New PDF Document
14
+
15
+ ```typescript
16
+ import { PDFDocument } from "@peculiar/pdf-core";
17
+
18
+ // Create a new PDF document
19
+ const doc = PDFDocument.create();
20
+
21
+ // Add a new page
22
+ await doc.addPage();
23
+
24
+ // Convert to PDF buffer
25
+ const pdfBuffer = await doc.toPDF();
26
+ ```
27
+
28
+ ### Reading an Existing PDF
29
+
30
+ ```typescript
31
+ import { PDFDocument } from "@peculiar/pdf-core";
32
+
33
+ // Read from buffer or string
34
+ const doc = await PDFDocument.fromPDF(existingPdfBuffer);
35
+
36
+ // Get the catalog
37
+ const catalog = doc.catalog;
38
+ ```
39
+
40
+ ### Working with Objects
41
+
42
+ ```typescript
43
+ import { PDFDocument } from "@peculiar/pdf-core";
44
+
45
+ const doc = PDFDocument.create();
46
+
47
+ // Create basic objects
48
+ const numberObj = doc.createNumber(42);
49
+ const stringObj = doc.createString("Hello, PDF!");
50
+ const arrayObj = doc.createArray(doc.createNumber(1), doc.createString("item"));
51
+
52
+ // Create a dictionary
53
+ const dictObj = doc.createDictionary(
54
+ ["Key1", doc.createNumber(1)],
55
+ ["Key2", doc.createString("value")]
56
+ );
57
+
58
+ // Create stream
59
+ const streamObj = doc.createStream(new Uint8Array([1, 2, 3, 4]));
60
+
61
+ // Make objects indirect
62
+ const indirectObj = numberObj.makeIndirect();
63
+ ```
64
+
65
+ ### Incremental Updates
66
+
67
+ The library supports incremental updates, allowing you to modify PDF documents without rewriting the entire file. This approach preserves the original document's history and is more efficient for changes.
68
+
69
+ ```typescript
70
+ const doc = await PDFDocument.fromPDF(existingPdfBuffer);
71
+
72
+ // Create new incremental update
73
+ await doc.createUpdate();
74
+
75
+ // Make modifications
76
+ const page = await doc.addPage();
77
+ // ... make other changes ...
78
+
79
+ // Save with incremental update
80
+ const updatedPdf = await doc.toPDF();
81
+ ```
82
+
83
+ ### XRef Support
84
+
85
+ The library handles both main XRef formats:
86
+
87
+ - Traditional XRef tables
88
+ - XRef streams (PDF 1.5+)
89
+
90
+ Both formats are automatically detected and processed when reading PDFs, and the library can write in either format.
91
+
92
+ ### Encryption
93
+
94
+ The library implements a comprehensive Encryption Handler based on WebCrypto API, supporting both password protection and certificate-based (PKI) encryption methods. You can secure PDF documents with user and owner passwords, or use X.509 certificates for PKI-based encryption with granular permission controls.
95
+
96
+ ## License
97
+
98
+ This project is dual-licensed under the AGPL-3.0 and a Commercial License:
99
+
100
+ ### AGPL-3.0
101
+
102
+ The library is open-source and freely available under the terms of the Affero General Public License (AGPL-3.0). This ensures that modifications and usage in network-based applications (e.g., SaaS) must be shared under the same license.
103
+
104
+ You can use the library under AGPL-3.0 if:
105
+
106
+ - Your project is open-source and distributed under a compatible license
107
+ - Your use complies with the AGPL-3.0 requirements
108
+
109
+ ### Commercial License
110
+
111
+ For use in proprietary, closed-source, or commercial projects where the AGPL is not suitable, a commercial license is available. This allows you to use the library without the AGPL's obligations.