unpdf 1.9.1 → 2.0.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 +97 -195
- package/dist/index.d.mts +123 -118
- package/dist/index.mjs +429 -223
- package/dist/pdfjs.mjs +6 -6
- package/package.json +14 -31
- package/dist/index.cjs +0 -449
- package/dist/index.d.cts +0 -180
- package/dist/pdfjs.d.ts +0 -1
package/dist/index.d.cts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { DocumentInitParameters, PDFDocumentProxy } from "./types/src/display/api.js";
|
|
2
|
-
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
3
|
-
import { Metadata } from "./types/src/display/metadata.js";
|
|
4
|
-
import * as PDFJS from "./types/src/pdf.js";
|
|
5
|
-
//#region src/_internal/canvas.d.ts
|
|
6
|
-
interface CanvasFactoryContext {
|
|
7
|
-
canvas?: HTMLCanvasElement | Canvas;
|
|
8
|
-
context?: CanvasRenderingContext2D | SKRSContext2D | null;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Derived from the PDF.js project by the Mozilla Foundation.
|
|
12
|
-
* @see https://github.com/mozilla/pdf.js/blob/b8de9a372f9bbf7e33adb362eeae5ef1919dba73/src/display/canvas_factory.js#L18
|
|
13
|
-
* @license Apache-2.0
|
|
14
|
-
*/
|
|
15
|
-
declare class BaseCanvasFactory {
|
|
16
|
-
#private;
|
|
17
|
-
constructor({ enableHWA }?: {
|
|
18
|
-
enableHWA?: boolean | undefined;
|
|
19
|
-
});
|
|
20
|
-
create(width: number, height: number): {
|
|
21
|
-
canvas: Canvas | HTMLCanvasElement;
|
|
22
|
-
context: SKRSContext2D | CanvasRenderingContext2D | null;
|
|
23
|
-
};
|
|
24
|
-
reset({ canvas }: CanvasFactoryContext, width: number, height: number): void;
|
|
25
|
-
destroy(context: CanvasFactoryContext): void;
|
|
26
|
-
_createCanvas(width: number, height: number): HTMLCanvasElement | Canvas;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Derived from the PDF.js project by the Mozilla Foundation.
|
|
30
|
-
* @see https://github.com/mozilla/pdf.js/blob/b8de9a372f9bbf7e33adb362eeae5ef1919dba73/src/display/canvas_factory.js#L18
|
|
31
|
-
* @license Apache-2.0
|
|
32
|
-
*/
|
|
33
|
-
declare class DOMCanvasFactory extends BaseCanvasFactory {
|
|
34
|
-
_document: Document;
|
|
35
|
-
constructor({ ownerDocument, enableHWA }?: {
|
|
36
|
-
ownerDocument?: Document | undefined;
|
|
37
|
-
enableHWA?: boolean | undefined;
|
|
38
|
-
});
|
|
39
|
-
_createCanvas(width: number, height: number): HTMLCanvasElement;
|
|
40
|
-
}
|
|
41
|
-
declare class NodeCanvasFactory extends BaseCanvasFactory {
|
|
42
|
-
constructor({ enableHWA }?: {
|
|
43
|
-
enableHWA?: boolean | undefined;
|
|
44
|
-
});
|
|
45
|
-
_createCanvas(width: number, height: number): Canvas;
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/image.d.ts
|
|
49
|
-
interface ExtractedImageObject {
|
|
50
|
-
data: Uint8ClampedArray;
|
|
51
|
-
width: number;
|
|
52
|
-
height: number;
|
|
53
|
-
channels: 1 | 3 | 4;
|
|
54
|
-
key: string;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Extracts images from a specific page of a PDF document, including necessary metadata,
|
|
58
|
-
* such as width, height, and calculated color channels.
|
|
59
|
-
*/
|
|
60
|
-
declare function extractImages$1(data: DocumentInitParameters['data'] | PDFDocumentProxy, pageNumber: number): Promise<ExtractedImageObject[]>;
|
|
61
|
-
declare function renderPageAsImage$1(data: DocumentInitParameters['data'] | PDFDocumentProxy, pageNumber: number, options?: {
|
|
62
|
-
canvasImport?: () => Promise<typeof import('@napi-rs/canvas')>;
|
|
63
|
-
/** @default 1.0 */
|
|
64
|
-
scale?: number;
|
|
65
|
-
width?: number;
|
|
66
|
-
height?: number;
|
|
67
|
-
toDataURL?: false;
|
|
68
|
-
}): Promise<ArrayBuffer>;
|
|
69
|
-
declare function renderPageAsImage$1(data: DocumentInitParameters['data'] | PDFDocumentProxy, pageNumber: number, options: {
|
|
70
|
-
canvasImport?: () => Promise<typeof import('@napi-rs/canvas')>;
|
|
71
|
-
/** @default 1.0 */
|
|
72
|
-
scale?: number;
|
|
73
|
-
width?: number;
|
|
74
|
-
height?: number;
|
|
75
|
-
toDataURL: true;
|
|
76
|
-
}): Promise<string>;
|
|
77
|
-
export declare function createIsomorphicCanvasFactory(canvasImport?: () => Promise<typeof import('@napi-rs/canvas')>): Promise<typeof DOMCanvasFactory | typeof NodeCanvasFactory>;
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/links.d.ts
|
|
80
|
-
declare function extractLinks$1(data: DocumentInitParameters['data'] | PDFDocumentProxy): Promise<{
|
|
81
|
-
totalPages: number;
|
|
82
|
-
links: string[];
|
|
83
|
-
}>;
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/meta.d.ts
|
|
86
|
-
declare function getMeta$1(data: DocumentInitParameters['data'] | PDFDocumentProxy, options?: {
|
|
87
|
-
parseDates?: boolean;
|
|
88
|
-
}): Promise<{
|
|
89
|
-
info: Record<string, any>;
|
|
90
|
-
metadata: Metadata;
|
|
91
|
-
}>;
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/text.d.ts
|
|
94
|
-
interface StructuredTextItem {
|
|
95
|
-
/** Text content. */
|
|
96
|
-
str: string;
|
|
97
|
-
/** X position in PDF coordinate space (origin: bottom-left). */
|
|
98
|
-
x: number;
|
|
99
|
-
/** Y position in PDF coordinate space (origin: bottom-left). */
|
|
100
|
-
y: number;
|
|
101
|
-
/** Width in device space. */
|
|
102
|
-
width: number;
|
|
103
|
-
/** Height in device space. */
|
|
104
|
-
height: number;
|
|
105
|
-
/** Font size derived from the transformation matrix. */
|
|
106
|
-
fontSize: number;
|
|
107
|
-
/** Font family resolved from the page's style table, empty when unknown. */
|
|
108
|
-
fontFamily: string;
|
|
109
|
-
/** Text direction: `"ltr"`, `"rtl"`, or `"ttb"`. */
|
|
110
|
-
dir: string;
|
|
111
|
-
/** Whether the text item is followed by a line break. */
|
|
112
|
-
hasEOL: boolean;
|
|
113
|
-
}
|
|
114
|
-
declare function extractTextItems$1(data: DocumentInitParameters['data'] | PDFDocumentProxy): Promise<{
|
|
115
|
-
totalPages: number;
|
|
116
|
-
items: StructuredTextItem[][];
|
|
117
|
-
}>;
|
|
118
|
-
declare function extractText$1(data: DocumentInitParameters['data'] | PDFDocumentProxy, options?: {
|
|
119
|
-
mergePages?: false;
|
|
120
|
-
}): Promise<{
|
|
121
|
-
totalPages: number;
|
|
122
|
-
text: string[];
|
|
123
|
-
}>;
|
|
124
|
-
declare function extractText$1(data: DocumentInitParameters['data'] | PDFDocumentProxy, options: {
|
|
125
|
-
mergePages: true;
|
|
126
|
-
}): Promise<{
|
|
127
|
-
totalPages: number;
|
|
128
|
-
text: string;
|
|
129
|
-
}>;
|
|
130
|
-
declare function extractText$1(data: DocumentInitParameters['data'] | PDFDocumentProxy, options?: {
|
|
131
|
-
mergePages?: boolean;
|
|
132
|
-
}): Promise<{
|
|
133
|
-
totalPages: number;
|
|
134
|
-
text: string | string[];
|
|
135
|
-
}>;
|
|
136
|
-
//#endregion
|
|
137
|
-
//#region src/config.d.ts
|
|
138
|
-
/**
|
|
139
|
-
* Sets the PDF.js build every other method uses – call it before any of them.
|
|
140
|
-
* Without it, the serverless build is used.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* // In Node.js, the legacy build of `pdfjs-dist` (install it first)
|
|
144
|
-
* import { definePDFJSModule } from 'unpdf'
|
|
145
|
-
*
|
|
146
|
-
* await definePDFJSModule(() => import('pdfjs-dist/legacy/build/pdf.mjs'))
|
|
147
|
-
*/
|
|
148
|
-
export declare function definePDFJSModule(pdfjs: () => Promise<any>): Promise<void>;
|
|
149
|
-
/** @deprecated Use `definePDFJSModule` instead. Will be removed in v2. */
|
|
150
|
-
export declare function configureUnPDF(options: {
|
|
151
|
-
pdfjs?: () => Promise<any>;
|
|
152
|
-
}): Promise<void>;
|
|
153
|
-
//#endregion
|
|
154
|
-
//#region src/utils.d.ts
|
|
155
|
-
/**
|
|
156
|
-
* Creates a `PDFDocumentProxy` from binary PDF data.
|
|
157
|
-
*
|
|
158
|
-
* Applies the following defaults:
|
|
159
|
-
* - `useSystemFonts: true`
|
|
160
|
-
*
|
|
161
|
-
* In Node.js environments, additionally applies:
|
|
162
|
-
* - `disableFontFace: true`
|
|
163
|
-
* - `standardFontDataUrl` resolved from the local `pdfjs-dist` package
|
|
164
|
-
* - `cMapUrl` and `cMapPacked` resolved from the local `pdfjs-dist` package
|
|
165
|
-
*/
|
|
166
|
-
export declare function getDocumentProxy(data: DocumentInitParameters['data'], options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
|
|
167
|
-
export declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
|
|
168
|
-
export declare function resolvePDFJSImport(pdfjsResolver?: () => Promise<any>, { reload }?: {
|
|
169
|
-
reload?: boolean | undefined;
|
|
170
|
-
}): Promise<void>;
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/index.d.ts
|
|
173
|
-
export declare const getMeta: typeof getMeta$1;
|
|
174
|
-
export declare const extractText: typeof extractText$1;
|
|
175
|
-
export declare const extractTextItems: typeof extractTextItems$1;
|
|
176
|
-
export declare const extractImages: typeof extractImages$1;
|
|
177
|
-
export declare const renderPageAsImage: typeof renderPageAsImage$1;
|
|
178
|
-
export declare const extractLinks: typeof extractLinks$1;
|
|
179
|
-
//#endregion
|
|
180
|
-
export type { StructuredTextItem };
|
package/dist/pdfjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types/src/pdf.js'
|