@f-o-t/pdf 0.1.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 +39 -0
- package/dist/generation/index.d.ts +268 -0
- package/dist/generation/index.js +26 -0
- package/dist/index.d.ts +808 -0
- package/dist/index.js +111 -0
- package/dist/parsing/index.d.ts +234 -0
- package/dist/parsing/index.js +16 -0
- package/dist/shared/chunk-10ftnz45.js +572 -0
- package/dist/shared/chunk-37mjkw9w.js +492 -0
- package/dist/shared/chunk-6dengthp.js +48 -0
- package/package.json +88 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @f-o-t/pdf
|
|
2
|
+
|
|
3
|
+
Comprehensive PDF 1.7 library with generation, parsing, and digital signatures.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Complete PDF 1.7 Support**: Full spec implementation
|
|
8
|
+
- **Generation**: Create PDFs from scratch with text, graphics, images
|
|
9
|
+
- **Parsing**: Read and extract content from PDFs
|
|
10
|
+
- **Digital Signatures**: Sign PDFs with @f-o-t/digital-certificate
|
|
11
|
+
- **Zod-First**: Complete validation
|
|
12
|
+
- **TypeScript-First**: Full type safety
|
|
13
|
+
- **Stream Support**: Memory-efficient processing
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @f-o-t/pdf
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { createPDF } from "@f-o-t/pdf";
|
|
25
|
+
|
|
26
|
+
const pdf = createPDF();
|
|
27
|
+
pdf.addPage()
|
|
28
|
+
.drawText("Hello, World!", { x: 50, y: 750 });
|
|
29
|
+
|
|
30
|
+
const bytes = await pdf.save();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
34
|
+
|
|
35
|
+
Coming soon.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
MIT
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF reference to indirect object
|
|
3
|
+
*/
|
|
4
|
+
type PDFRef = {
|
|
5
|
+
readonly objectNumber: number;
|
|
6
|
+
readonly generation: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* PDF value types
|
|
10
|
+
*/
|
|
11
|
+
type PDFValue = boolean | number | string | PDFName | PDFArray | PDFDictionary | PDFStream | null | PDFRef;
|
|
12
|
+
/**
|
|
13
|
+
* PDF Name object
|
|
14
|
+
*/
|
|
15
|
+
type PDFName = {
|
|
16
|
+
readonly type: "name";
|
|
17
|
+
readonly value: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* PDF Array
|
|
21
|
+
*/
|
|
22
|
+
type PDFArray = PDFValue[];
|
|
23
|
+
/**
|
|
24
|
+
* PDF Dictionary
|
|
25
|
+
*/
|
|
26
|
+
type PDFDictionary = Record<string, PDFValue>;
|
|
27
|
+
/**
|
|
28
|
+
* PDF Stream
|
|
29
|
+
*/
|
|
30
|
+
type PDFStream = {
|
|
31
|
+
readonly dictionary: PDFDictionary;
|
|
32
|
+
readonly data: Uint8Array;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* PDF Page size presets
|
|
36
|
+
*/
|
|
37
|
+
type PageSize = "A4" | "Letter" | "Legal" | "A3" | "A5" | "Tabloid" | {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* PDF Color
|
|
43
|
+
*/
|
|
44
|
+
type PDFColor = {
|
|
45
|
+
type: "rgb";
|
|
46
|
+
r: number;
|
|
47
|
+
g: number;
|
|
48
|
+
b: number;
|
|
49
|
+
} | {
|
|
50
|
+
type: "cmyk";
|
|
51
|
+
c: number;
|
|
52
|
+
m: number;
|
|
53
|
+
y: number;
|
|
54
|
+
k: number;
|
|
55
|
+
} | {
|
|
56
|
+
type: "gray";
|
|
57
|
+
gray: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Text options
|
|
61
|
+
*/
|
|
62
|
+
type TextOptions = {
|
|
63
|
+
x: number;
|
|
64
|
+
y: number;
|
|
65
|
+
size?: number;
|
|
66
|
+
font?: string;
|
|
67
|
+
color?: PDFColor;
|
|
68
|
+
align?: "left" | "center" | "right";
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Rectangle options
|
|
72
|
+
*/
|
|
73
|
+
type RectOptions = {
|
|
74
|
+
x: number;
|
|
75
|
+
y: number;
|
|
76
|
+
width: number;
|
|
77
|
+
height: number;
|
|
78
|
+
fill?: PDFColor;
|
|
79
|
+
stroke?: PDFColor;
|
|
80
|
+
lineWidth?: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Line options
|
|
84
|
+
*/
|
|
85
|
+
type LineOptions = {
|
|
86
|
+
x1: number;
|
|
87
|
+
y1: number;
|
|
88
|
+
x2: number;
|
|
89
|
+
y2: number;
|
|
90
|
+
color?: PDFColor;
|
|
91
|
+
lineWidth?: number;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* PDF metadata
|
|
95
|
+
*/
|
|
96
|
+
type PDFMetadata = {
|
|
97
|
+
title?: string;
|
|
98
|
+
author?: string;
|
|
99
|
+
subject?: string;
|
|
100
|
+
keywords?: string[];
|
|
101
|
+
creator?: string;
|
|
102
|
+
producer?: string;
|
|
103
|
+
creationDate?: Date;
|
|
104
|
+
modificationDate?: Date;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* PDF version
|
|
108
|
+
*/
|
|
109
|
+
type PDFVersion = "1.4" | "1.5" | "1.6" | "1.7";
|
|
110
|
+
type PDFPageOptions = {
|
|
111
|
+
size?: PageSize;
|
|
112
|
+
parent?: PDFRef;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* PDF Page class
|
|
116
|
+
*/
|
|
117
|
+
declare class PDFPage {
|
|
118
|
+
ref: PDFRef;
|
|
119
|
+
size: PageSize;
|
|
120
|
+
parent?: PDFRef;
|
|
121
|
+
contentStream: string[];
|
|
122
|
+
private resources;
|
|
123
|
+
constructor(ref: PDFRef, options?: PDFPageOptions);
|
|
124
|
+
/**
|
|
125
|
+
* Get page dimensions in points
|
|
126
|
+
*/
|
|
127
|
+
getDimensions(): {
|
|
128
|
+
width: number;
|
|
129
|
+
height: number;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Set fill color
|
|
133
|
+
*/
|
|
134
|
+
private setFillColor;
|
|
135
|
+
/**
|
|
136
|
+
* Set stroke color
|
|
137
|
+
*/
|
|
138
|
+
private setStrokeColor;
|
|
139
|
+
/**
|
|
140
|
+
* Draw text on the page
|
|
141
|
+
*/
|
|
142
|
+
drawText(text: string, options: TextOptions): void;
|
|
143
|
+
/**
|
|
144
|
+
* Draw a rectangle
|
|
145
|
+
*/
|
|
146
|
+
drawRectangle(options: RectOptions): void;
|
|
147
|
+
/**
|
|
148
|
+
* Draw a line
|
|
149
|
+
*/
|
|
150
|
+
drawLine(options: LineOptions): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get content stream reference
|
|
153
|
+
*/
|
|
154
|
+
getContentStreamRef(): PDFRef;
|
|
155
|
+
/**
|
|
156
|
+
* Generate content stream as PDFStream
|
|
157
|
+
*/
|
|
158
|
+
toContentStream(): PDFStream;
|
|
159
|
+
/**
|
|
160
|
+
* Convert page to PDF dictionary
|
|
161
|
+
*/
|
|
162
|
+
toDictionary(): PDFDictionary;
|
|
163
|
+
}
|
|
164
|
+
type PDFDocumentOptions = {
|
|
165
|
+
version?: PDFVersion;
|
|
166
|
+
metadata?: PDFMetadata;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Main PDF Document class for generation
|
|
170
|
+
*
|
|
171
|
+
* @property version - PDF version (1.4, 1.5, 1.6, or 1.7)
|
|
172
|
+
* @property metadata - Document metadata (title, author, etc.)
|
|
173
|
+
* @property catalog - Reference to the document catalog
|
|
174
|
+
* @property pages - Reference to the pages tree root
|
|
175
|
+
*/
|
|
176
|
+
declare class PDFDocument {
|
|
177
|
+
version: PDFVersion;
|
|
178
|
+
metadata: PDFMetadata;
|
|
179
|
+
private objects;
|
|
180
|
+
private nextObjectNumber;
|
|
181
|
+
catalog: PDFRef;
|
|
182
|
+
pages: PDFRef;
|
|
183
|
+
private pagesArray;
|
|
184
|
+
constructor(options?: PDFDocumentOptions);
|
|
185
|
+
/**
|
|
186
|
+
* Allocate a new object reference
|
|
187
|
+
*/
|
|
188
|
+
private allocateRef;
|
|
189
|
+
/**
|
|
190
|
+
* Add a page to the document
|
|
191
|
+
*/
|
|
192
|
+
addPage(options?: PDFPageOptions): PDFPage;
|
|
193
|
+
/**
|
|
194
|
+
* Save PDF to bytes
|
|
195
|
+
*/
|
|
196
|
+
save(): Uint8Array;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* PDF Standard 14 Fonts
|
|
200
|
+
* These fonts are guaranteed to be available in all PDF readers
|
|
201
|
+
*/
|
|
202
|
+
declare const STANDARD_FONTS: {
|
|
203
|
+
readonly "Times-Roman": "Times-Roman";
|
|
204
|
+
readonly "Times-Bold": "Times-Bold";
|
|
205
|
+
readonly "Times-Italic": "Times-Italic";
|
|
206
|
+
readonly "Times-BoldItalic": "Times-BoldItalic";
|
|
207
|
+
readonly Helvetica: "Helvetica";
|
|
208
|
+
readonly "Helvetica-Bold": "Helvetica-Bold";
|
|
209
|
+
readonly "Helvetica-Oblique": "Helvetica-Oblique";
|
|
210
|
+
readonly "Helvetica-BoldOblique": "Helvetica-BoldOblique";
|
|
211
|
+
readonly Courier: "Courier";
|
|
212
|
+
readonly "Courier-Bold": "Courier-Bold";
|
|
213
|
+
readonly "Courier-Oblique": "Courier-Oblique";
|
|
214
|
+
readonly "Courier-BoldOblique": "Courier-BoldOblique";
|
|
215
|
+
readonly Symbol: "Symbol";
|
|
216
|
+
readonly ZapfDingbats: "ZapfDingbats";
|
|
217
|
+
};
|
|
218
|
+
type StandardFont = keyof typeof STANDARD_FONTS;
|
|
219
|
+
/**
|
|
220
|
+
* Font families for convenience
|
|
221
|
+
*/
|
|
222
|
+
declare const FONT_FAMILIES: {
|
|
223
|
+
times: {
|
|
224
|
+
regular: StandardFont;
|
|
225
|
+
bold: StandardFont;
|
|
226
|
+
italic: StandardFont;
|
|
227
|
+
boldItalic: StandardFont;
|
|
228
|
+
};
|
|
229
|
+
helvetica: {
|
|
230
|
+
regular: StandardFont;
|
|
231
|
+
bold: StandardFont;
|
|
232
|
+
oblique: StandardFont;
|
|
233
|
+
boldOblique: StandardFont;
|
|
234
|
+
};
|
|
235
|
+
courier: {
|
|
236
|
+
regular: StandardFont;
|
|
237
|
+
bold: StandardFont;
|
|
238
|
+
oblique: StandardFont;
|
|
239
|
+
boldOblique: StandardFont;
|
|
240
|
+
};
|
|
241
|
+
symbol: {
|
|
242
|
+
regular: StandardFont;
|
|
243
|
+
};
|
|
244
|
+
zapfDingbats: {
|
|
245
|
+
regular: StandardFont;
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Check if a font is a standard PDF font
|
|
250
|
+
*/
|
|
251
|
+
declare function isStandardFont(font: string): font is StandardFont;
|
|
252
|
+
/**
|
|
253
|
+
* Get font object reference name
|
|
254
|
+
*/
|
|
255
|
+
declare function getFontRefName(font: StandardFont): string;
|
|
256
|
+
/**
|
|
257
|
+
* Serialize a PDF value to string
|
|
258
|
+
*/
|
|
259
|
+
declare function serializeValue(value: PDFValue): string;
|
|
260
|
+
/**
|
|
261
|
+
* Serialize a PDF stream
|
|
262
|
+
*/
|
|
263
|
+
declare function serializeStream(stream: PDFStream): Uint8Array;
|
|
264
|
+
/**
|
|
265
|
+
* Serialize an indirect object
|
|
266
|
+
*/
|
|
267
|
+
declare function serializeObject(objectNumber: number, generation: number, value: any): Uint8Array;
|
|
268
|
+
export { serializeValue, serializeStream, serializeObject, isStandardFont, getFontRefName, StandardFont, STANDARD_FONTS, PDFPageOptions, PDFPage, PDFDocumentOptions, PDFDocument, FONT_FAMILIES };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FONT_FAMILIES,
|
|
3
|
+
PDFDocument,
|
|
4
|
+
PDFPage,
|
|
5
|
+
STANDARD_FONTS,
|
|
6
|
+
getFontRefName,
|
|
7
|
+
isStandardFont,
|
|
8
|
+
serializeObject,
|
|
9
|
+
serializeStream,
|
|
10
|
+
serializeValue
|
|
11
|
+
} from "../shared/chunk-37mjkw9w.js";
|
|
12
|
+
import"../shared/chunk-6dengthp.js";
|
|
13
|
+
export {
|
|
14
|
+
serializeValue,
|
|
15
|
+
serializeStream,
|
|
16
|
+
serializeObject,
|
|
17
|
+
isStandardFont,
|
|
18
|
+
getFontRefName,
|
|
19
|
+
STANDARD_FONTS,
|
|
20
|
+
PDFPage,
|
|
21
|
+
PDFDocument,
|
|
22
|
+
FONT_FAMILIES
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# debugId=3E109D686F511FD064756E2164756E21
|
|
26
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFtdLAogICJzb3VyY2VzQ29udGVudCI6IFsKICBdLAogICJtYXBwaW5ncyI6ICIiLAogICJkZWJ1Z0lkIjogIjNFMTA5RDY4NkY1MTFGRDA2NDc1NkUyMTY0NzU2RTIxIiwKICAibmFtZXMiOiBbXQp9
|