@lexmata/micropdf 0.4.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.
Files changed (170) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +985 -0
  3. package/binding.gyp +73 -0
  4. package/dist/annot.d.ts +458 -0
  5. package/dist/annot.d.ts.map +1 -0
  6. package/dist/annot.js +697 -0
  7. package/dist/annot.js.map +1 -0
  8. package/dist/archive.d.ts +128 -0
  9. package/dist/archive.d.ts.map +1 -0
  10. package/dist/archive.js +268 -0
  11. package/dist/archive.js.map +1 -0
  12. package/dist/buffer.d.ts +572 -0
  13. package/dist/buffer.d.ts.map +1 -0
  14. package/dist/buffer.js +971 -0
  15. package/dist/buffer.js.map +1 -0
  16. package/dist/colorspace.d.ts +287 -0
  17. package/dist/colorspace.d.ts.map +1 -0
  18. package/dist/colorspace.js +542 -0
  19. package/dist/colorspace.js.map +1 -0
  20. package/dist/context.d.ts +184 -0
  21. package/dist/context.d.ts.map +1 -0
  22. package/dist/context.js +320 -0
  23. package/dist/context.js.map +1 -0
  24. package/dist/cookie.d.ts +164 -0
  25. package/dist/cookie.d.ts.map +1 -0
  26. package/dist/cookie.js +306 -0
  27. package/dist/cookie.js.map +1 -0
  28. package/dist/device.d.ts +169 -0
  29. package/dist/device.d.ts.map +1 -0
  30. package/dist/device.js +350 -0
  31. package/dist/device.js.map +1 -0
  32. package/dist/display-list.d.ts +202 -0
  33. package/dist/display-list.d.ts.map +1 -0
  34. package/dist/display-list.js +410 -0
  35. package/dist/display-list.js.map +1 -0
  36. package/dist/document.d.ts +637 -0
  37. package/dist/document.d.ts.map +1 -0
  38. package/dist/document.js +902 -0
  39. package/dist/document.js.map +1 -0
  40. package/dist/easy.d.ts +423 -0
  41. package/dist/easy.d.ts.map +1 -0
  42. package/dist/easy.js +644 -0
  43. package/dist/easy.js.map +1 -0
  44. package/dist/enhanced.d.ts +226 -0
  45. package/dist/enhanced.d.ts.map +1 -0
  46. package/dist/enhanced.js +368 -0
  47. package/dist/enhanced.js.map +1 -0
  48. package/dist/filter.d.ts +51 -0
  49. package/dist/filter.d.ts.map +1 -0
  50. package/dist/filter.js +381 -0
  51. package/dist/filter.js.map +1 -0
  52. package/dist/font.d.ts +222 -0
  53. package/dist/font.d.ts.map +1 -0
  54. package/dist/font.js +381 -0
  55. package/dist/font.js.map +1 -0
  56. package/dist/form.d.ts +214 -0
  57. package/dist/form.d.ts.map +1 -0
  58. package/dist/form.js +497 -0
  59. package/dist/form.js.map +1 -0
  60. package/dist/geometry.d.ts +469 -0
  61. package/dist/geometry.d.ts.map +1 -0
  62. package/dist/geometry.js +780 -0
  63. package/dist/geometry.js.map +1 -0
  64. package/dist/image.d.ts +172 -0
  65. package/dist/image.d.ts.map +1 -0
  66. package/dist/image.js +348 -0
  67. package/dist/image.js.map +1 -0
  68. package/dist/index.d.ts +171 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +339 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/link.d.ts +168 -0
  73. package/dist/link.d.ts.map +1 -0
  74. package/dist/link.js +343 -0
  75. package/dist/link.js.map +1 -0
  76. package/dist/micropdf.d.ts +40 -0
  77. package/dist/micropdf.d.ts.map +1 -0
  78. package/dist/micropdf.js +45 -0
  79. package/dist/micropdf.js.map +1 -0
  80. package/dist/nanopdf.d.ts +40 -0
  81. package/dist/nanopdf.d.ts.map +1 -0
  82. package/dist/nanopdf.js +45 -0
  83. package/dist/nanopdf.js.map +1 -0
  84. package/dist/native.d.ts +242 -0
  85. package/dist/native.d.ts.map +1 -0
  86. package/dist/native.js +509 -0
  87. package/dist/native.js.map +1 -0
  88. package/dist/output.d.ts +166 -0
  89. package/dist/output.d.ts.map +1 -0
  90. package/dist/output.js +365 -0
  91. package/dist/output.js.map +1 -0
  92. package/dist/path.d.ts +420 -0
  93. package/dist/path.d.ts.map +1 -0
  94. package/dist/path.js +687 -0
  95. package/dist/path.js.map +1 -0
  96. package/dist/pdf/object.d.ts +489 -0
  97. package/dist/pdf/object.d.ts.map +1 -0
  98. package/dist/pdf/object.js +1045 -0
  99. package/dist/pdf/object.js.map +1 -0
  100. package/dist/pixmap.d.ts +315 -0
  101. package/dist/pixmap.d.ts.map +1 -0
  102. package/dist/pixmap.js +590 -0
  103. package/dist/pixmap.js.map +1 -0
  104. package/dist/profiler.d.ts +159 -0
  105. package/dist/profiler.d.ts.map +1 -0
  106. package/dist/profiler.js +380 -0
  107. package/dist/profiler.js.map +1 -0
  108. package/dist/render-options.d.ts +227 -0
  109. package/dist/render-options.d.ts.map +1 -0
  110. package/dist/render-options.js +130 -0
  111. package/dist/render-options.js.map +1 -0
  112. package/dist/resource-tracking.d.ts +332 -0
  113. package/dist/resource-tracking.d.ts.map +1 -0
  114. package/dist/resource-tracking.js +653 -0
  115. package/dist/resource-tracking.js.map +1 -0
  116. package/dist/simple.d.ts +276 -0
  117. package/dist/simple.d.ts.map +1 -0
  118. package/dist/simple.js +343 -0
  119. package/dist/simple.js.map +1 -0
  120. package/dist/stext.d.ts +290 -0
  121. package/dist/stext.d.ts.map +1 -0
  122. package/dist/stext.js +312 -0
  123. package/dist/stext.js.map +1 -0
  124. package/dist/stream.d.ts +174 -0
  125. package/dist/stream.d.ts.map +1 -0
  126. package/dist/stream.js +476 -0
  127. package/dist/stream.js.map +1 -0
  128. package/dist/text.d.ts +337 -0
  129. package/dist/text.d.ts.map +1 -0
  130. package/dist/text.js +454 -0
  131. package/dist/text.js.map +1 -0
  132. package/dist/typed-arrays.d.ts +127 -0
  133. package/dist/typed-arrays.d.ts.map +1 -0
  134. package/dist/typed-arrays.js +410 -0
  135. package/dist/typed-arrays.js.map +1 -0
  136. package/dist/types.d.ts +358 -0
  137. package/dist/types.d.ts.map +1 -0
  138. package/dist/types.js +216 -0
  139. package/dist/types.js.map +1 -0
  140. package/native/annot.cc +557 -0
  141. package/native/buffer.cc +204 -0
  142. package/native/colorspace.cc +166 -0
  143. package/native/context.cc +84 -0
  144. package/native/cookie.cc +179 -0
  145. package/native/device.cc +179 -0
  146. package/native/display_list.cc +179 -0
  147. package/native/document.cc +268 -0
  148. package/native/enhanced.cc +70 -0
  149. package/native/font.cc +282 -0
  150. package/native/form.cc +523 -0
  151. package/native/geometry.cc +255 -0
  152. package/native/image.cc +216 -0
  153. package/native/include/micropdf/enhanced.h +38 -0
  154. package/native/include/micropdf/types.h +36 -0
  155. package/native/include/micropdf.h +106 -0
  156. package/native/include/mupdf-ffi.h +39 -0
  157. package/native/include/mupdf.h +11 -0
  158. package/native/include/mupdf_minimal.h +381 -0
  159. package/native/lib/linux-x64/libmicropdf.a +0 -0
  160. package/native/link.cc +234 -0
  161. package/native/micropdf.cc +71 -0
  162. package/native/output.cc +229 -0
  163. package/native/page.cc +572 -0
  164. package/native/path.cc +259 -0
  165. package/native/pixmap.cc +240 -0
  166. package/native/stext.cc +610 -0
  167. package/native/stream.cc +239 -0
  168. package/package.json +120 -0
  169. package/scripts/build-from-rust.js +97 -0
  170. package/scripts/install.js +184 -0
@@ -0,0 +1,637 @@
1
+ /**
2
+ * Document - PDF document handling
3
+ *
4
+ * This module provides the primary API for working with PDF documents. It handles
5
+ * document lifecycle, page access, metadata, security, and rendering operations.
6
+ *
7
+ * This implementation mirrors the Rust `fitz::document::Document` for 100% API compatibility.
8
+ *
9
+ * @module document
10
+ * @example
11
+ * ```typescript
12
+ * import { Document } from 'micropdf';
13
+ *
14
+ * // Open a PDF from a file
15
+ * const doc = Document.open('document.pdf');
16
+ *
17
+ * // Check if password is required
18
+ * if (doc.needsPassword()) {
19
+ * doc.authenticate('password');
20
+ * }
21
+ *
22
+ * // Get page count
23
+ * console.log(`Pages: ${doc.pageCount}`);
24
+ *
25
+ * // Load and render a page
26
+ * const page = doc.loadPage(0);
27
+ * const pixmap = page.toPixmap(Matrix.identity());
28
+ *
29
+ * // Extract text
30
+ * const text = page.extractText();
31
+ *
32
+ * // Clean up
33
+ * page.drop();
34
+ * doc.close();
35
+ * ```
36
+ */
37
+ import { Buffer } from './buffer.js';
38
+ import { Colorspace } from './colorspace.js';
39
+ import { Rect, Quad } from './geometry.js';
40
+ import type { NativeContext, NativePage } from './native.js';
41
+ import { Pixmap } from './pixmap.js';
42
+ import { type RenderOptions, type ExtendedRenderOptions } from './render-options.js';
43
+ import { type Link, type RectLike, type MatrixLike } from './types.js';
44
+ /**
45
+ * An item in the document outline (table of contents / bookmarks).
46
+ *
47
+ * Outline items form a tree structure representing the document's navigation hierarchy.
48
+ * Each item can link to a page number, URI, or have child items.
49
+ *
50
+ * @class OutlineItem
51
+ * @example
52
+ * ```typescript
53
+ * const outline = doc.getOutline();
54
+ * for (const item of outline) {
55
+ * console.log(`${item.title} -> Page ${item.page}`);
56
+ * for (const child of item.children) {
57
+ * console.log(` ${child.title} -> Page ${child.page}`);
58
+ * }
59
+ * }
60
+ * ```
61
+ */
62
+ export declare class OutlineItem {
63
+ /**
64
+ * The title/label of this outline item.
65
+ * @readonly
66
+ * @type {string}
67
+ */
68
+ readonly title: string;
69
+ /**
70
+ * The destination page number (0-indexed), if this item links to a page.
71
+ * Undefined if this item links to a URI instead.
72
+ * @readonly
73
+ * @type {number | undefined}
74
+ */
75
+ readonly page: number | undefined;
76
+ /**
77
+ * The destination URI, if this item links to an external resource.
78
+ * Undefined if this item links to a page instead.
79
+ * @readonly
80
+ * @type {string | undefined}
81
+ */
82
+ readonly uri: string | undefined;
83
+ /**
84
+ * Child outline items nested under this item.
85
+ * @readonly
86
+ * @type {OutlineItem[]}
87
+ */
88
+ readonly children: OutlineItem[];
89
+ /**
90
+ * Creates a new outline item.
91
+ *
92
+ * @param {string} title - The title of the outline item
93
+ * @param {number} [page] - The destination page number (0-indexed)
94
+ * @param {string} [uri] - The destination URI
95
+ */
96
+ constructor(title: string, page?: number, uri?: string);
97
+ }
98
+ /**
99
+ * A block of text extracted from a PDF page.
100
+ *
101
+ * Text blocks represent cohesive units of text, typically paragraphs or sections.
102
+ * They contain the bounding box, complete text, and structured line information.
103
+ *
104
+ * @interface TextBlock
105
+ * @example
106
+ * ```typescript
107
+ * const blocks = page.extractTextBlocks();
108
+ * for (const block of blocks) {
109
+ * console.log(`Block at [${block.bbox.x0}, ${block.bbox.y0}]:`);
110
+ * console.log(block.text);
111
+ * console.log(`Contains ${block.lines.length} lines`);
112
+ * }
113
+ * ```
114
+ */
115
+ export interface TextBlock {
116
+ /**
117
+ * The bounding box of the entire text block.
118
+ * @readonly
119
+ * @type {RectLike}
120
+ */
121
+ readonly bbox: RectLike;
122
+ /**
123
+ * The complete text content of this block.
124
+ * @readonly
125
+ * @type {string}
126
+ */
127
+ readonly text: string;
128
+ /**
129
+ * The individual lines within this block.
130
+ * @readonly
131
+ * @type {TextLine[]}
132
+ */
133
+ readonly lines: TextLine[];
134
+ }
135
+ /**
136
+ * A single line of text extracted from a PDF page.
137
+ *
138
+ * Text lines represent a horizontal run of text, typically corresponding to
139
+ * a single line in the original document layout.
140
+ *
141
+ * @interface TextLine
142
+ * @example
143
+ * ```typescript
144
+ * const blocks = page.extractTextBlocks();
145
+ * for (const block of blocks) {
146
+ * for (const line of block.lines) {
147
+ * console.log(`Line: "${line.text}"`);
148
+ * console.log(` Font sizes: ${line.spans.map(s => s.size).join(', ')}`);
149
+ * }
150
+ * }
151
+ * ```
152
+ */
153
+ export interface TextLine {
154
+ /**
155
+ * The bounding box of the entire line.
156
+ * @readonly
157
+ * @type {RectLike}
158
+ */
159
+ readonly bbox: RectLike;
160
+ /**
161
+ * The complete text content of this line.
162
+ * @readonly
163
+ * @type {string}
164
+ */
165
+ readonly text: string;
166
+ /**
167
+ * The individual text spans within this line.
168
+ * @readonly
169
+ * @type {TextSpan[]}
170
+ */
171
+ readonly spans: TextSpan[];
172
+ }
173
+ /**
174
+ * A span of text with consistent formatting properties.
175
+ *
176
+ * Text spans represent runs of text that share the same font, size, and color.
177
+ * They are the most granular level of text extraction.
178
+ *
179
+ * @interface TextSpan
180
+ * @example
181
+ * ```typescript
182
+ * const blocks = page.extractTextBlocks();
183
+ * for (const block of blocks) {
184
+ * for (const line of block.lines) {
185
+ * for (const span of line.spans) {
186
+ * console.log(`"${span.text}" - ${span.font} @ ${span.size}pt`);
187
+ * console.log(` Color: RGB(${span.color.join(', ')})`);
188
+ * }
189
+ * }
190
+ * }
191
+ * ```
192
+ */
193
+ export interface TextSpan {
194
+ /**
195
+ * The bounding box of this text span.
196
+ * @readonly
197
+ * @type {RectLike}
198
+ */
199
+ readonly bbox: RectLike;
200
+ /**
201
+ * The text content of this span.
202
+ * @readonly
203
+ * @type {string}
204
+ */
205
+ readonly text: string;
206
+ /**
207
+ * The font name used for this span.
208
+ * @readonly
209
+ * @type {string}
210
+ */
211
+ readonly font: string;
212
+ /**
213
+ * The font size in points.
214
+ * @readonly
215
+ * @type {number}
216
+ */
217
+ readonly size: number;
218
+ /**
219
+ * The text color as RGB values (0-255).
220
+ * @readonly
221
+ * @type {number[]}
222
+ */
223
+ readonly color: number[];
224
+ }
225
+ /**
226
+ * A page in a PDF document.
227
+ *
228
+ * Represents a single page within a PDF document with methods for rendering,
229
+ * text extraction, search, and link retrieval. Pages are loaded from a Document
230
+ * using `Document.loadPage()`.
231
+ *
232
+ * **Important**: Pages must be explicitly freed using `drop()` when no longer needed
233
+ * to prevent memory leaks.
234
+ *
235
+ * @class Page
236
+ * @example
237
+ * ```typescript
238
+ * const doc = Document.open('document.pdf');
239
+ * const page = doc.loadPage(0); // Load first page
240
+ *
241
+ * try {
242
+ * // Get page dimensions
243
+ * console.log(`Size: ${page.bounds.width} x ${page.bounds.height}`);
244
+ * console.log(`Rotation: ${page.rotation}°`);
245
+ *
246
+ * // Extract text
247
+ * const text = page.extractText();
248
+ * console.log(text);
249
+ *
250
+ * // Search for text
251
+ * const hits = page.searchText('hello');
252
+ * console.log(`Found ${hits.length} occurrences`);
253
+ *
254
+ * // Render to pixmap
255
+ * const matrix = Matrix.scale(2, 2); // 2x zoom
256
+ * const pixmap = page.toPixmap(matrix);
257
+ * } finally {
258
+ * page.drop(); // Always clean up!
259
+ * }
260
+ *
261
+ * doc.close();
262
+ * ```
263
+ */
264
+ export declare class Page {
265
+ /** @internal - Native context handle */
266
+ _ctx?: NativeContext | undefined;
267
+ /** @internal - Native page handle */
268
+ _page?: NativePage | undefined;
269
+ private readonly _pageNumber;
270
+ private readonly _bounds;
271
+ private readonly _mediaBox;
272
+ private readonly _rotation;
273
+ /** @internal */
274
+ constructor(_document: Document, pageNumber: number, bounds: Rect, mediaBox: Rect, rotation: number, ctx?: NativeContext, page?: NativePage);
275
+ /**
276
+ * Get the page number (0-based)
277
+ */
278
+ get pageNumber(): number;
279
+ /**
280
+ * Get the page bounds
281
+ */
282
+ get bounds(): Rect;
283
+ /**
284
+ * Get the media box
285
+ */
286
+ get mediaBox(): Rect;
287
+ /**
288
+ * Get the crop box
289
+ */
290
+ get cropBox(): Rect;
291
+ /**
292
+ * Get the page rotation (0, 90, 180, or 270)
293
+ */
294
+ get rotation(): number;
295
+ /**
296
+ * Render the page to a pixmap using FFI
297
+ * @throws Error when native bindings are not available
298
+ */
299
+ toPixmap(matrix?: MatrixLike, colorspace?: Colorspace, alpha?: boolean): Pixmap;
300
+ /**
301
+ * Render the page to PNG using FFI
302
+ * @throws Error when native bindings are not available
303
+ */
304
+ toPNG(dpi?: number): Uint8Array;
305
+ /**
306
+ * Render page with advanced options
307
+ *
308
+ * Provides fine-grained control over rendering quality, colorspace,
309
+ * anti-aliasing, and other rendering parameters.
310
+ *
311
+ * @param options - Rendering options
312
+ * @returns Pixmap containing the rendered page
313
+ * @throws Error if native bindings are not available
314
+ * @throws Error if options are invalid
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * // High-quality print rendering
319
+ * const pixmap = page.renderWithOptions({
320
+ * dpi: 300,
321
+ * colorspace: Colorspace.deviceRGB(),
322
+ * alpha: true,
323
+ * antiAlias: AntiAliasLevel.High
324
+ * });
325
+ *
326
+ * // Fast preview rendering
327
+ * const preview = page.renderWithOptions({
328
+ * dpi: 72,
329
+ * antiAlias: AntiAliasLevel.Low
330
+ * });
331
+ * ```
332
+ */
333
+ renderWithOptions(options?: RenderOptions): Pixmap;
334
+ /**
335
+ * Render page with progress tracking
336
+ *
337
+ * Extended rendering with progress callbacks and timeout support.
338
+ * Useful for long-running renders of complex pages.
339
+ *
340
+ * @param options - Extended rendering options with callbacks
341
+ * @returns Promise resolving to the rendered pixmap
342
+ * @throws Error if rendering fails or times out
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * const pixmap = await page.renderWithProgress({
347
+ * dpi: 600,
348
+ * onProgress: (current, total) => {
349
+ * console.log(`Rendering: ${Math.round(current/total * 100)}%`);
350
+ * return true; // Continue rendering
351
+ * },
352
+ * onError: (error) => {
353
+ * console.error('Render error:', error);
354
+ * },
355
+ * timeout: 30000 // 30 second timeout
356
+ * });
357
+ * ```
358
+ */
359
+ renderWithProgress(options?: ExtendedRenderOptions): Promise<Pixmap>;
360
+ /**
361
+ * Extract text from the page using FFI
362
+ * @throws Error when native bindings are not available
363
+ */
364
+ getText(): string;
365
+ /**
366
+ * Get text blocks from the page using FFI
367
+ * @throws Error when native bindings are not available
368
+ */
369
+ getTextBlocks(): TextBlock[];
370
+ /**
371
+ * Get links from the page using FFI
372
+ * @throws Error when native bindings are not available
373
+ */
374
+ getLinks(): Link[];
375
+ /**
376
+ * Search for text on the page using FFI
377
+ * @throws Error when native bindings are not available
378
+ */
379
+ search(needle: string): Quad[];
380
+ /**
381
+ * Search for text on the page (alias for search)
382
+ */
383
+ searchText(needle: string): Quad[];
384
+ /**
385
+ * Extract text from the page (alias for getText for MuPDF API compatibility)
386
+ */
387
+ extractText(): string;
388
+ /**
389
+ * Extract text blocks from the page (alias for getTextBlocks for MuPDF API compatibility)
390
+ */
391
+ extractTextBlocks(): TextBlock[];
392
+ /**
393
+ * Drop/release the page resources
394
+ */
395
+ drop(): void;
396
+ }
397
+ /**
398
+ * A PDF or other supported document format.
399
+ *
400
+ * The Document class is the main entry point for working with PDF files. It provides
401
+ * methods for opening documents from files or memory, accessing pages, checking security,
402
+ * reading metadata, and performing document-level operations.
403
+ *
404
+ * **Supported formats**: PDF, XPS, CBZ, and other formats supported by MuPDF.
405
+ *
406
+ * **Resource Management**: Documents must be explicitly closed using `close()` when
407
+ * done to free native resources and prevent memory leaks.
408
+ *
409
+ * @class Document
410
+ * @example
411
+ * ```typescript
412
+ * // Open from file
413
+ * const doc = Document.open('document.pdf');
414
+ *
415
+ * // Open from buffer
416
+ * const buffer = fs.readFileSync('document.pdf');
417
+ * const doc2 = Document.openFromBuffer(buffer);
418
+ *
419
+ * // Check basic info
420
+ * console.log(`Pages: ${doc.pageCount}`);
421
+ * console.log(`Title: ${doc.getMetadata('Title')}`);
422
+ * console.log(`Author: ${doc.getMetadata('Author')}`);
423
+ *
424
+ * // Handle password-protected PDFs
425
+ * if (doc.needsPassword()) {
426
+ * const success = doc.authenticate('password123');
427
+ * if (!success) {
428
+ * throw new Error('Invalid password');
429
+ * }
430
+ * }
431
+ *
432
+ * // Check permissions
433
+ * if (!doc.hasPermission(4)) { // FZ_PERMISSION_PRINT
434
+ * console.warn('Printing is not allowed');
435
+ * }
436
+ *
437
+ * // Work with pages
438
+ * for (let i = 0; i < doc.pageCount; i++) {
439
+ * const page = doc.loadPage(i);
440
+ * const text = page.extractText();
441
+ * console.log(`Page ${i + 1}: ${text.substring(0, 100)}...`);
442
+ * page.drop();
443
+ * }
444
+ *
445
+ * // Save modified document
446
+ * doc.save('output.pdf');
447
+ *
448
+ * // Always clean up
449
+ * doc.close();
450
+ * ```
451
+ *
452
+ * @example
453
+ * ```typescript
454
+ * // Using try-finally for proper cleanup
455
+ * const doc = Document.open('document.pdf');
456
+ * try {
457
+ * // Work with document
458
+ * const page = doc.loadPage(0);
459
+ * try {
460
+ * const text = page.extractText();
461
+ * console.log(text);
462
+ * } finally {
463
+ * page.drop();
464
+ * }
465
+ * } finally {
466
+ * doc.close();
467
+ * }
468
+ * ```
469
+ */
470
+ export declare class Document {
471
+ private _ctx?;
472
+ private _doc?;
473
+ private _pages;
474
+ private readonly _format;
475
+ private readonly _metadata;
476
+ private readonly _outline;
477
+ private _needsPassword;
478
+ private _isAuthenticated;
479
+ private constructor();
480
+ /**
481
+ * Open a document from a file path
482
+ * Uses native FFI bindings when available for full rendering support
483
+ */
484
+ static open(path: string, password?: string): Document;
485
+ /**
486
+ * Open a document from a buffer
487
+ * Uses native FFI bindings when available for full rendering support
488
+ */
489
+ static fromBuffer(buffer: Buffer, password?: string): Document;
490
+ /**
491
+ * Open a document from a Uint8Array
492
+ */
493
+ static fromUint8Array(data: Uint8Array, password?: string): Document;
494
+ /**
495
+ * Get the page count
496
+ */
497
+ get pageCount(): number;
498
+ /**
499
+ * Get the document format (e.g., "PDF 1.4")
500
+ */
501
+ get format(): string;
502
+ /**
503
+ * Check if the document needs a password
504
+ */
505
+ get needsPassword(): boolean;
506
+ /**
507
+ * Check if the document is authenticated
508
+ */
509
+ get isAuthenticated(): boolean;
510
+ /**
511
+ * Check if the document is a PDF
512
+ */
513
+ get isPDF(): boolean;
514
+ /**
515
+ * Check if the document is reflowable (e.g., EPUB)
516
+ */
517
+ get isReflowable(): boolean;
518
+ /**
519
+ * Authenticate with a password using FFI
520
+ * @returns true if authentication successful
521
+ * @throws Error when native bindings are not available
522
+ */
523
+ authenticate(password: string): boolean;
524
+ /**
525
+ * Check if the document has a specific permission using FFI
526
+ * @param permission The permission to check (print, edit, copy, annotate)
527
+ * @throws Error when native bindings are not available
528
+ */
529
+ hasPermission(permission: string): boolean;
530
+ /**
531
+ * Get page label for a given page number
532
+ * @param pageNum Page number (0-based)
533
+ * @returns Page label (e.g., "i", "ii", "1", "2", "A-1")
534
+ */
535
+ getPageLabel(pageNum: number): string;
536
+ /**
537
+ * Get page number from a page label
538
+ * @param label Page label to look up
539
+ * @returns Page number (0-based) or -1 if not found
540
+ */
541
+ getPageFromLabel(label: string): number;
542
+ /**
543
+ * Check if the document is valid (not corrupted)
544
+ */
545
+ isValid(): boolean;
546
+ /**
547
+ * Resolve a named destination to a page location using FFI
548
+ * @param name Named destination (e.g., "section1", "chapter2")
549
+ * @returns Page number (0-based) or undefined if not found
550
+ * @throws Error when native bindings are not available
551
+ */
552
+ resolveNamedDest(name: string): number | undefined;
553
+ /**
554
+ * Count chapters in the document (for structured documents)
555
+ */
556
+ countChapters(): number;
557
+ /**
558
+ * Count pages in a specific chapter
559
+ * @param chapterIndex Chapter index (0-based)
560
+ */
561
+ countChapterPages(chapterIndex: number): number;
562
+ /**
563
+ * Get page number from a chapter and page location
564
+ * @param chapter Chapter index (0-based)
565
+ * @param page Page within chapter (0-based)
566
+ */
567
+ pageNumberFromLocation(chapter: number, page: number): number;
568
+ /**
569
+ * Layout the document with specific width and height (for reflowable documents)
570
+ * @param width Target width
571
+ * @param height Target height
572
+ * @param em Font size in points
573
+ */
574
+ layout(_width: number, _height: number, _em?: number): void;
575
+ /**
576
+ * Clone the document (create a copy)
577
+ * Note: This creates a shallow copy sharing the same data
578
+ */
579
+ clone(): Document;
580
+ /**
581
+ * Get a page by index
582
+ */
583
+ getPage(index: number): Page;
584
+ /**
585
+ * Load a page by index (alias for getPage for MuPDF API compatibility)
586
+ */
587
+ loadPage(index: number): Page;
588
+ /**
589
+ * Check if the document needs a password (method form for API compatibility)
590
+ */
591
+ needsPasswordCheck(): boolean;
592
+ /**
593
+ * Close the document and release resources
594
+ */
595
+ close(): void;
596
+ /**
597
+ * Iterate over all pages
598
+ */
599
+ pages(): Generator<Page>;
600
+ /**
601
+ * Get the document outline (table of contents)
602
+ */
603
+ getOutline(): OutlineItem[];
604
+ /**
605
+ * Get metadata value
606
+ */
607
+ getMetadata(key: string): string | undefined;
608
+ /**
609
+ * Set metadata value
610
+ */
611
+ setMetadata(key: string, value: string): void;
612
+ /**
613
+ * Get the title
614
+ */
615
+ get title(): string | undefined;
616
+ /**
617
+ * Get the author
618
+ */
619
+ get author(): string | undefined;
620
+ /**
621
+ * Get the subject
622
+ */
623
+ get subject(): string | undefined;
624
+ /**
625
+ * Get the keywords
626
+ */
627
+ get keywords(): string | undefined;
628
+ /**
629
+ * Get the creator application
630
+ */
631
+ get creator(): string | undefined;
632
+ /**
633
+ * Get the producer application
634
+ */
635
+ get producer(): string | undefined;
636
+ }
637
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAU,IAAI,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAkB,UAAU,EAAc,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAI3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA+B,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpG;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,WAAW;IACtB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAElC;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC;IAEjC;;;;;;OAMG;gBACS,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;CAMvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,SAAS;IACxB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