pdfium-native 0.1.1
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 +21 -0
- package/README.md +227 -0
- package/binding.gyp +85 -0
- package/dist/document.d.ts +23 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +36 -0
- package/dist/document.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +58 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/page.d.ts +40 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +59 -0
- package/dist/page.js.map +1 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/lib/__tests__/document.test.ts +99 -0
- package/lib/__tests__/features.test.ts +72 -0
- package/lib/__tests__/fixtures.ts +71 -0
- package/lib/__tests__/load.test.ts +68 -0
- package/lib/__tests__/page.test.ts +123 -0
- package/lib/__tests__/render.test.ts +103 -0
- package/lib/__tests__/search.test.ts +44 -0
- package/lib/document.ts +40 -0
- package/lib/errors.ts +63 -0
- package/lib/index.ts +63 -0
- package/lib/page.ts +80 -0
- package/lib/types.ts +154 -0
- package/package.json +80 -0
- package/scripts/bundle-lib.mjs +66 -0
- package/scripts/download-pdfium.mjs +84 -0
- package/scripts/generate-fixtures.mjs +194 -0
- package/scripts/install.mjs +80 -0
- package/src/document.h +254 -0
- package/src/napi_helpers.h +50 -0
- package/src/page.h +576 -0
- package/src/pdfium_addon.cc +218 -0
- package/src/render_worker.h +141 -0
- package/src/stb_image_write.c +2 -0
- package/src/stb_image_write.h +1724 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xonaman
|
|
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,227 @@
|
|
|
1
|
+
# pdfium-native
|
|
2
|
+
|
|
3
|
+
Native Node.js bindings for [PDFium](https://pdfium.googlesource.com/pdfium/) — Google's open-source PDF rendering engine. Built as a C++ addon using N-API for full ABI stability across Node.js versions.
|
|
4
|
+
|
|
5
|
+
All expensive operations are async (runs on the libuv thread pool), so the main thread is never blocked.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install pdfium-native
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Prebuilt PDFium binaries are downloaded automatically during install. A C++ compiler is required (Xcode CLI tools on macOS, `build-essential` on Linux, Visual Studio on Windows).
|
|
14
|
+
|
|
15
|
+
## Supported Platforms
|
|
16
|
+
|
|
17
|
+
| OS | Architectures |
|
|
18
|
+
| --------------------- | ---------------------- |
|
|
19
|
+
| macOS | arm64, x64 |
|
|
20
|
+
| Linux (glibc) | x64, arm64, arm, ppc64 |
|
|
21
|
+
| Linux (musl / Alpine) | x64, arm64 |
|
|
22
|
+
| Windows | x64, arm64 |
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { loadDocument } from 'pdfium-native';
|
|
28
|
+
|
|
29
|
+
const doc = await loadDocument('invoice.pdf');
|
|
30
|
+
const page = await doc.getPage(0);
|
|
31
|
+
|
|
32
|
+
// extract text
|
|
33
|
+
const text = page.getText();
|
|
34
|
+
|
|
35
|
+
// render to buffer
|
|
36
|
+
const jpeg = await page.render({ scale: 3, format: 'jpeg', quality: 90 });
|
|
37
|
+
|
|
38
|
+
// render to file
|
|
39
|
+
await page.render({ scale: 4, format: 'png', output: 'page-0.png' });
|
|
40
|
+
|
|
41
|
+
page.close();
|
|
42
|
+
doc.destroy();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### `loadDocument(input, password?)`
|
|
48
|
+
|
|
49
|
+
Opens a PDF from a `Buffer` or file path string. Returns `Promise<PDFiumDocument>`.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const doc = await loadDocument(buffer);
|
|
53
|
+
const doc = await loadDocument('/path/to/file.pdf');
|
|
54
|
+
const doc = await loadDocument(buffer, 'secret');
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### PDFiumDocument
|
|
60
|
+
|
|
61
|
+
| Property | Type | Description |
|
|
62
|
+
| ----------- | ------------------ | --------------------------------------- |
|
|
63
|
+
| `pageCount` | `number` | Total number of pages. |
|
|
64
|
+
| `metadata` | `DocumentMetadata` | Title, author, dates, PDF version, etc. |
|
|
65
|
+
|
|
66
|
+
#### `getPage(index)`
|
|
67
|
+
|
|
68
|
+
Loads a page by 0-based index. Returns `Promise<PDFiumPage>`.
|
|
69
|
+
|
|
70
|
+
#### `pages()`
|
|
71
|
+
|
|
72
|
+
Async generator that yields every page. Caller must close each page.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
for await (const page of doc.pages()) {
|
|
76
|
+
console.log(page.getText());
|
|
77
|
+
page.close();
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### `getBookmarks()`
|
|
82
|
+
|
|
83
|
+
Returns the bookmark/outline tree as `Bookmark[]`.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
interface Bookmark {
|
|
87
|
+
title: string;
|
|
88
|
+
pageIndex?: number;
|
|
89
|
+
children?: Bookmark[];
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### `destroy()`
|
|
94
|
+
|
|
95
|
+
Closes the document and frees all native resources. Must be called when done.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
### PDFiumPage
|
|
100
|
+
|
|
101
|
+
| Property | Type | Description |
|
|
102
|
+
| ------------- | ------------------- | --------------------------------------------------- |
|
|
103
|
+
| `width` | `number` | Page width in points (1 pt = 1/72 inch). |
|
|
104
|
+
| `height` | `number` | Page height in points. |
|
|
105
|
+
| `size` | `{ width, height }` | Page dimensions. |
|
|
106
|
+
| `number` | `number` | 0-based page index. |
|
|
107
|
+
| `objectCount` | `number` | Number of page objects (text, images, paths, etc.). |
|
|
108
|
+
|
|
109
|
+
#### `getText()`
|
|
110
|
+
|
|
111
|
+
Extracts all text from the page as a string.
|
|
112
|
+
|
|
113
|
+
#### `render(options?)`
|
|
114
|
+
|
|
115
|
+
Renders the page to an encoded image. Returns `Promise<Buffer>`, or `Promise<void>` when `output` is specified.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
interface PageRenderOptions {
|
|
119
|
+
scale?: number; // default: 1 (72 DPI). Use 3–4 for print quality.
|
|
120
|
+
width?: number; // override render width in pixels
|
|
121
|
+
height?: number; // override render height in pixels
|
|
122
|
+
format?: 'jpeg' | 'png'; // default: 'jpeg'
|
|
123
|
+
quality?: number; // JPEG quality 1–100 (default: 100)
|
|
124
|
+
output?: string; // write to file instead of returning a Buffer
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### `getObject(index)`
|
|
129
|
+
|
|
130
|
+
Returns the page object at the given index. Objects are discriminated by `type`:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
type PageObject = TextPageObject | ImagePageObject | OtherPageObject;
|
|
134
|
+
|
|
135
|
+
// all objects have:
|
|
136
|
+
// bounds: { left, bottom, right, top }
|
|
137
|
+
// fillColor: { r, g, b, a } | null
|
|
138
|
+
// strokeColor: { r, g, b, a } | null
|
|
139
|
+
|
|
140
|
+
// type: 'text' adds: text, fontSize, fontName
|
|
141
|
+
// type: 'image' adds: imageWidth, imageHeight
|
|
142
|
+
// type: 'path' | 'shading' | 'form' | 'unknown'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### `getLinks()`
|
|
146
|
+
|
|
147
|
+
Returns all links on the page as `Link[]`.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
interface Link {
|
|
151
|
+
bounds?: { left; bottom; right; top };
|
|
152
|
+
url?: string; // external URL
|
|
153
|
+
pageIndex?: number; // internal link target
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### `search(text, options?)`
|
|
158
|
+
|
|
159
|
+
Searches for text on the page. Returns matches with character positions and bounding rectangles.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
const matches = page.search('invoice', { caseSensitive: true, wholeWord: false });
|
|
163
|
+
// [{ charIndex: 42, length: 7, rects: [{ left, top, right, bottom }] }]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### `getAnnotations()`
|
|
167
|
+
|
|
168
|
+
Returns all annotations on the page as `Annotation[]`.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
interface Annotation {
|
|
172
|
+
type: 'text' | 'link' | 'highlight' | 'underline' | 'strikeout' | /* ... */ 'unknown';
|
|
173
|
+
bounds?: { left; bottom; right; top };
|
|
174
|
+
contents: string;
|
|
175
|
+
color: { r; g; b; a } | null;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### `close()`
|
|
180
|
+
|
|
181
|
+
Closes the page and frees resources. Must be called when done with the page.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### DocumentMetadata
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
interface DocumentMetadata {
|
|
189
|
+
title: string;
|
|
190
|
+
author: string;
|
|
191
|
+
subject: string;
|
|
192
|
+
keywords: string;
|
|
193
|
+
creator: string;
|
|
194
|
+
producer: string;
|
|
195
|
+
creationDate: string;
|
|
196
|
+
modDate: string;
|
|
197
|
+
pdfVersion: number; // e.g. 17 for PDF 1.7
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Acknowledgements
|
|
204
|
+
|
|
205
|
+
This project uses prebuilt PDFium binaries from [bblanchon/pdfium-binaries](https://github.com/bblanchon/pdfium-binaries), which provides automated builds of the PDFium library for multiple platforms. Thanks to [@bblanchon](https://github.com/bblanchon) for maintaining this invaluable resource.
|
|
206
|
+
|
|
207
|
+
## Memory Management
|
|
208
|
+
|
|
209
|
+
Always call `page.close()` and `doc.destroy()` when done. PDFium allocates native memory that is not tracked by the garbage collector.
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const doc = await loadDocument('file.pdf');
|
|
213
|
+
try {
|
|
214
|
+
const page = await doc.getPage(0);
|
|
215
|
+
try {
|
|
216
|
+
// use page
|
|
217
|
+
} finally {
|
|
218
|
+
page.close();
|
|
219
|
+
}
|
|
220
|
+
} finally {
|
|
221
|
+
doc.destroy();
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "pdfium",
|
|
5
|
+
"sources": [
|
|
6
|
+
"src/pdfium_addon.cc",
|
|
7
|
+
"src/stb_image_write.c"
|
|
8
|
+
],
|
|
9
|
+
"include_dirs": [
|
|
10
|
+
"<!@(node -p \"require('node-addon-api').include\")",
|
|
11
|
+
"deps/pdfium/include",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"defines": [
|
|
15
|
+
"NAPI_VERSION=8"
|
|
16
|
+
],
|
|
17
|
+
"cflags!": [
|
|
18
|
+
"-fno-exceptions"
|
|
19
|
+
],
|
|
20
|
+
"cflags_cc!": [
|
|
21
|
+
"-fno-exceptions"
|
|
22
|
+
],
|
|
23
|
+
"cflags_cc": [
|
|
24
|
+
"-std=c++17"
|
|
25
|
+
],
|
|
26
|
+
"conditions": [
|
|
27
|
+
[
|
|
28
|
+
"OS=='mac'",
|
|
29
|
+
{
|
|
30
|
+
"xcode_settings": {
|
|
31
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
32
|
+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
|
|
33
|
+
"OTHER_LDFLAGS": [
|
|
34
|
+
"-L<(module_root_dir)/deps/pdfium/lib",
|
|
35
|
+
"-lpdfium",
|
|
36
|
+
"-Wl,-rpath,@loader_path",
|
|
37
|
+
"-framework CoreFoundation",
|
|
38
|
+
"-framework CoreGraphics"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"OS=='linux'",
|
|
45
|
+
{
|
|
46
|
+
"libraries": [
|
|
47
|
+
"-L<(module_root_dir)/deps/pdfium/lib",
|
|
48
|
+
"-lpdfium",
|
|
49
|
+
"-Wl,-rpath,'$$ORIGIN'",
|
|
50
|
+
"-lpthread",
|
|
51
|
+
"-ldl"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"OS=='win'",
|
|
57
|
+
{
|
|
58
|
+
"defines": [
|
|
59
|
+
"_HAS_EXCEPTIONS=1"
|
|
60
|
+
],
|
|
61
|
+
"msvs_settings": {
|
|
62
|
+
"VCCLCompilerTool": {
|
|
63
|
+
"ExceptionHandling": 1,
|
|
64
|
+
"AdditionalOptions": [
|
|
65
|
+
"/std:c++17"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"libraries": [
|
|
70
|
+
"<(module_root_dir)/deps/pdfium/lib/pdfium.dll.lib"
|
|
71
|
+
],
|
|
72
|
+
"copies": [
|
|
73
|
+
{
|
|
74
|
+
"destination": "<(module_root_dir)/build/Release",
|
|
75
|
+
"files": [
|
|
76
|
+
"<(module_root_dir)/deps/pdfium/bin/pdfium.dll"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PDFiumPage } from './page.js';
|
|
2
|
+
import type { Bookmark, DocumentMetadata, NativeDocument } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A loaded PDF document.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PDFiumDocument {
|
|
7
|
+
private native;
|
|
8
|
+
/** Total number of pages. */
|
|
9
|
+
readonly pageCount: number;
|
|
10
|
+
/** Document metadata (title, author, dates, etc.). */
|
|
11
|
+
readonly metadata: DocumentMetadata;
|
|
12
|
+
/** @internal */
|
|
13
|
+
constructor(native: NativeDocument);
|
|
14
|
+
/** Gets a page by 0-based index. */
|
|
15
|
+
getPage(index: number): Promise<PDFiumPage>;
|
|
16
|
+
/** Iterates over all pages. Caller is responsible for closing each page. */
|
|
17
|
+
pages(): AsyncGenerator<PDFiumPage>;
|
|
18
|
+
/** Closes the document and frees all resources. */
|
|
19
|
+
destroy(): void;
|
|
20
|
+
/** Returns the bookmark/outline tree. */
|
|
21
|
+
getBookmarks(): Bookmark[];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7E;;GAEG;AACH,qBAAa,cAAc;IAOb,OAAO,CAAC,MAAM;IAN1B,6BAA6B;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB;gBACI,MAAM,EAAE,cAAc;IAK1C,oCAAoC;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjD,4EAA4E;IACrE,KAAK,IAAI,cAAc,CAAC,UAAU,CAAC;IAM1C,mDAAmD;IACnD,OAAO,IAAI,IAAI;IAIf,yCAAyC;IACzC,YAAY,IAAI,QAAQ,EAAE;CAG3B"}
|
package/dist/document.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PDFiumPage } from './page.js';
|
|
2
|
+
/**
|
|
3
|
+
* A loaded PDF document.
|
|
4
|
+
*/
|
|
5
|
+
export class PDFiumDocument {
|
|
6
|
+
native;
|
|
7
|
+
/** Total number of pages. */
|
|
8
|
+
pageCount;
|
|
9
|
+
/** Document metadata (title, author, dates, etc.). */
|
|
10
|
+
metadata;
|
|
11
|
+
/** @internal */
|
|
12
|
+
constructor(native) {
|
|
13
|
+
this.native = native;
|
|
14
|
+
this.pageCount = native.pageCount;
|
|
15
|
+
this.metadata = native.metadata;
|
|
16
|
+
}
|
|
17
|
+
/** Gets a page by 0-based index. */
|
|
18
|
+
async getPage(index) {
|
|
19
|
+
return new PDFiumPage(await this.native.getPage(index));
|
|
20
|
+
}
|
|
21
|
+
/** Iterates over all pages. Caller is responsible for closing each page. */
|
|
22
|
+
async *pages() {
|
|
23
|
+
for (let i = 0; i < this.pageCount; i++) {
|
|
24
|
+
yield this.getPage(i);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Closes the document and frees all resources. */
|
|
28
|
+
destroy() {
|
|
29
|
+
this.native.destroy();
|
|
30
|
+
}
|
|
31
|
+
/** Returns the bookmark/outline tree. */
|
|
32
|
+
getBookmarks() {
|
|
33
|
+
return this.native.getBookmarks();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC;;GAEG;AACH,MAAM,OAAO,cAAc;IAOL;IANpB,6BAA6B;IACpB,SAAS,CAAS;IAC3B,sDAAsD;IAC7C,QAAQ,CAAmB;IAEpC,gBAAgB;IAChB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;QACxC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED,oCAAoC;IACpC,KAAK,CAAC,OAAO,CAAC,KAAa;QACzB,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,4EAA4E;IAC5E,KAAK,CAAC,CAAC,KAAK;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,OAAO;QACL,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,yCAAyC;IACzC,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Base error for all PDFium operations. */
|
|
2
|
+
export declare class PDFiumError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(code: string, message: string);
|
|
5
|
+
}
|
|
6
|
+
/** Thrown when the file cannot be found or opened. */
|
|
7
|
+
export declare class PDFiumFileError extends PDFiumError {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/** Thrown when the input is not a valid PDF or is corrupted. */
|
|
11
|
+
export declare class PDFiumFormatError extends PDFiumError {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
/** Thrown when a password is required or incorrect. */
|
|
15
|
+
export declare class PDFiumPasswordError extends PDFiumError {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
/** Thrown when the PDF uses an unsupported security scheme. */
|
|
19
|
+
export declare class PDFiumSecurityError extends PDFiumError {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare function parseNativeError(err: unknown): PDFiumError;
|
|
23
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,sDAAsD;AACtD,qBAAa,eAAgB,SAAQ,WAAW;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED,gEAAgE;AAChE,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED,uDAAuD;AACvD,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,OAAO,EAAE,MAAM;CAI5B;AAED,+DAA+D;AAC/D,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAoB1D"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Base error for all PDFium operations. */
|
|
2
|
+
export class PDFiumError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'PDFiumError';
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Thrown when the file cannot be found or opened. */
|
|
11
|
+
export class PDFiumFileError extends PDFiumError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super('FILE', message);
|
|
14
|
+
this.name = 'PDFiumFileError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Thrown when the input is not a valid PDF or is corrupted. */
|
|
18
|
+
export class PDFiumFormatError extends PDFiumError {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super('FORMAT', message);
|
|
21
|
+
this.name = 'PDFiumFormatError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Thrown when a password is required or incorrect. */
|
|
25
|
+
export class PDFiumPasswordError extends PDFiumError {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super('PASSWORD', message);
|
|
28
|
+
this.name = 'PDFiumPasswordError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Thrown when the PDF uses an unsupported security scheme. */
|
|
32
|
+
export class PDFiumSecurityError extends PDFiumError {
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super('SECURITY', message);
|
|
35
|
+
this.name = 'PDFiumSecurityError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function parseNativeError(err) {
|
|
39
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
40
|
+
const colonIdx = msg.indexOf(':');
|
|
41
|
+
if (colonIdx === -1)
|
|
42
|
+
return new PDFiumError('UNKNOWN', msg);
|
|
43
|
+
const code = msg.slice(0, colonIdx);
|
|
44
|
+
const text = msg.slice(colonIdx + 1);
|
|
45
|
+
switch (code) {
|
|
46
|
+
case 'FILE':
|
|
47
|
+
return new PDFiumFileError(text);
|
|
48
|
+
case 'FORMAT':
|
|
49
|
+
return new PDFiumFormatError(text);
|
|
50
|
+
case 'PASSWORD':
|
|
51
|
+
return new PDFiumPasswordError(text);
|
|
52
|
+
case 'SECURITY':
|
|
53
|
+
return new PDFiumSecurityError(text);
|
|
54
|
+
default:
|
|
55
|
+
return new PDFiumError(code, text);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAS;IACtB,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,sDAAsD;AACtD,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,gEAAgE;AAChE,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,uDAAuD;AACvD,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,+DAA+D;AAC/D,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,WAAW,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAE5D,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IAErC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACnC,KAAK,QAAQ;YACX,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACrC,KAAK,UAAU;YACb,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACvC,KAAK,UAAU;YACb,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACvC;YACE,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PDFiumDocument } from './document.js';
|
|
2
|
+
type PdfInput = Buffer | string;
|
|
3
|
+
/**
|
|
4
|
+
* Opens a PDF document from a Buffer or file path.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadDocument(input: PdfInput, password?: string): Promise<PDFiumDocument>;
|
|
7
|
+
export { PDFiumDocument } from './document.js';
|
|
8
|
+
export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
|
|
9
|
+
export { PDFiumPage } from './page.js';
|
|
10
|
+
export type { Annotation, AnnotationType, Bookmark, DocumentMetadata, ImagePageObject, Link, OtherPageObject, PageObject, PageObjectBounds, PageObjectType, PageRenderOptions, PageSize, RGBA, SearchMatch, SearchOptions, SearchRect, TextPageObject, } from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAchC;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAM9F;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EACV,UAAU,EACV,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,EACV,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { PDFiumDocument } from './document.js';
|
|
5
|
+
import { parseNativeError } from './errors.js';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
// ensure the dynamic linker can find libpdfium next to pdfium.node.
|
|
9
|
+
// note: LD_LIBRARY_PATH is read at process startup, so this only helps
|
|
10
|
+
// child processes or dlopen calls that haven't been resolved yet.
|
|
11
|
+
const addonDir = resolve(__dirname, '..', 'build', 'Release');
|
|
12
|
+
if (process.platform === 'win32') {
|
|
13
|
+
process.env.PATH = `${addonDir};${process.env.PATH ?? ''}`;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
process.env.LD_LIBRARY_PATH = `${addonDir}:${process.env.LD_LIBRARY_PATH ?? ''}`;
|
|
17
|
+
}
|
|
18
|
+
const addon = require('../build/Release/pdfium.node');
|
|
19
|
+
/**
|
|
20
|
+
* Opens a PDF document from a Buffer or file path.
|
|
21
|
+
*/
|
|
22
|
+
export async function loadDocument(input, password) {
|
|
23
|
+
try {
|
|
24
|
+
return new PDFiumDocument(await addon.loadDocument(input, password));
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
throw parseNativeError(err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export { PDFiumDocument } from './document.js';
|
|
31
|
+
export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
|
|
32
|
+
export { PDFiumPage } from './page.js';
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAI1D,oEAAoE;AACpE,uEAAuE;AACvE,kEAAkE;AAClE,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAC9D,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;AAC7D,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,GAAG,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;AACnF,CAAC;AAED,MAAM,KAAK,GAAgB,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAAe,EAAE,QAAiB;IACnE,IAAI,CAAC;QACH,OAAO,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Annotation, Link, NativePage, PageObject, PageRenderOptions, PageSize, SearchMatch, SearchOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A page in a PDF document.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PDFiumPage {
|
|
6
|
+
private native;
|
|
7
|
+
/** Page width in points (1 pt = 1/72 inch). */
|
|
8
|
+
readonly width: number;
|
|
9
|
+
/** Page height in points (1 pt = 1/72 inch). */
|
|
10
|
+
readonly height: number;
|
|
11
|
+
/** Page dimensions in points. */
|
|
12
|
+
readonly size: PageSize;
|
|
13
|
+
/** 0-based page index. */
|
|
14
|
+
readonly number: number;
|
|
15
|
+
/** Number of page objects (text spans, paths, images, etc.). */
|
|
16
|
+
readonly objectCount: number;
|
|
17
|
+
/** @internal */
|
|
18
|
+
constructor(native: NativePage);
|
|
19
|
+
/** Extracts all text from the page. */
|
|
20
|
+
getText(): string;
|
|
21
|
+
/** Renders the page to a file. */
|
|
22
|
+
render(options: PageRenderOptions & {
|
|
23
|
+
output: string;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
/** Renders the page to an encoded image buffer (JPEG or PNG). */
|
|
26
|
+
render(options?: PageRenderOptions): Promise<Buffer>;
|
|
27
|
+
/** Returns the page object at the given index with type and bounds. */
|
|
28
|
+
getObject(index: number): PageObject;
|
|
29
|
+
/** Iterates over all page objects (text spans, paths, images, etc.). */
|
|
30
|
+
objects(): Generator<PageObject>;
|
|
31
|
+
/** Closes the page and frees resources. */
|
|
32
|
+
close(): void;
|
|
33
|
+
/** Returns all links on the page. */
|
|
34
|
+
getLinks(): Link[];
|
|
35
|
+
/** Searches for text on the page. Returns matches with positions and bounding rects. */
|
|
36
|
+
search(text: string, options?: SearchOptions): SearchMatch[];
|
|
37
|
+
/** Returns all annotations on the page. */
|
|
38
|
+
getAnnotations(): Annotation[];
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,IAAI,EACJ,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,UAAU;IAaT,OAAO,CAAC,MAAM;IAZ1B,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gBAAgB;gBACI,MAAM,EAAE,UAAU;IAQtC,uCAAuC;IACvC,OAAO,IAAI,MAAM;IAIjB,kCAAkC;IAClC,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IACtE,iEAAiE;IACjE,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAKpD,uEAAuE;IACvE,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAIpC,wEAAwE;IACvE,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC;IAMjC,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IAIb,qCAAqC;IACrC,QAAQ,IAAI,IAAI,EAAE;IAIlB,wFAAwF;IACxF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,WAAW,EAAE;IAI5D,2CAA2C;IAC3C,cAAc,IAAI,UAAU,EAAE;CAG/B"}
|
package/dist/page.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A page in a PDF document.
|
|
3
|
+
*/
|
|
4
|
+
export class PDFiumPage {
|
|
5
|
+
native;
|
|
6
|
+
/** Page width in points (1 pt = 1/72 inch). */
|
|
7
|
+
width;
|
|
8
|
+
/** Page height in points (1 pt = 1/72 inch). */
|
|
9
|
+
height;
|
|
10
|
+
/** Page dimensions in points. */
|
|
11
|
+
size;
|
|
12
|
+
/** 0-based page index. */
|
|
13
|
+
number;
|
|
14
|
+
/** Number of page objects (text spans, paths, images, etc.). */
|
|
15
|
+
objectCount;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor(native) {
|
|
18
|
+
this.native = native;
|
|
19
|
+
this.width = native.width;
|
|
20
|
+
this.height = native.height;
|
|
21
|
+
this.size = native.size;
|
|
22
|
+
this.number = native.number;
|
|
23
|
+
this.objectCount = native.objectCount;
|
|
24
|
+
}
|
|
25
|
+
/** Extracts all text from the page. */
|
|
26
|
+
getText() {
|
|
27
|
+
return this.native.getText();
|
|
28
|
+
}
|
|
29
|
+
render(options) {
|
|
30
|
+
return this.native.render(options);
|
|
31
|
+
}
|
|
32
|
+
/** Returns the page object at the given index with type and bounds. */
|
|
33
|
+
getObject(index) {
|
|
34
|
+
return this.native.getObject(index);
|
|
35
|
+
}
|
|
36
|
+
/** Iterates over all page objects (text spans, paths, images, etc.). */
|
|
37
|
+
*objects() {
|
|
38
|
+
for (let i = 0; i < this.objectCount; i++) {
|
|
39
|
+
yield this.getObject(i);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Closes the page and frees resources. */
|
|
43
|
+
close() {
|
|
44
|
+
this.native.close();
|
|
45
|
+
}
|
|
46
|
+
/** Returns all links on the page. */
|
|
47
|
+
getLinks() {
|
|
48
|
+
return this.native.getLinks();
|
|
49
|
+
}
|
|
50
|
+
/** Searches for text on the page. Returns matches with positions and bounding rects. */
|
|
51
|
+
search(text, options) {
|
|
52
|
+
return this.native.search(text, options);
|
|
53
|
+
}
|
|
54
|
+
/** Returns all annotations on the page. */
|
|
55
|
+
getAnnotations() {
|
|
56
|
+
return this.native.getAnnotations();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=page.js.map
|
package/dist/page.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAO,UAAU;IAaD;IAZpB,+CAA+C;IACtC,KAAK,CAAS;IACvB,gDAAgD;IACvC,MAAM,CAAS;IACxB,iCAAiC;IACxB,IAAI,CAAW;IACxB,0BAA0B;IACjB,MAAM,CAAS;IACxB,gEAAgE;IACvD,WAAW,CAAS;IAE7B,gBAAgB;IAChB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QACpC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACxC,CAAC;IAED,uCAAuC;IACvC,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAMD,MAAM,CAAC,OAA2B;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,uEAAuE;IACvE,SAAS,CAAC,KAAa;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,wEAAwE;IACxE,CAAC,OAAO;QACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,2CAA2C;IAC3C,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,qCAAqC;IACrC,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAED,wFAAwF;IACxF,MAAM,CAAC,IAAY,EAAE,OAAuB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,2CAA2C;IAC3C,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;CACF"}
|