@bentopdf/pymupdf-wasm 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/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@bentopdf/pymupdf-wasm",
3
+ "version": "0.1.1",
4
+ "description": "PyMuPDF compiled to WebAssembly - Full PDF manipulation in the browser",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./types/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "types",
18
+ "assets"
19
+ ],
20
+ "scripts": {
21
+ "build": "esbuild src/index.ts --bundle --format=esm --outfile=dist/index.js --external:./assets/* --external:@okathira/ghostpdl-wasm",
22
+ "dev": "esbuild src/index.ts --bundle --format=esm --outfile=dist/index.js --watch --external:@okathira/ghostpdl-wasm",
23
+ "typecheck": "tsc --noEmit"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/alam00000/bentopdf-pymupdf-wasm.git"
28
+ },
29
+ "keywords": [
30
+ "pdf",
31
+ "pymupdf",
32
+ "wasm",
33
+ "webassembly",
34
+ "pyodide",
35
+ "document",
36
+ "convert",
37
+ "merge",
38
+ "split",
39
+ "extract"
40
+ ],
41
+ "author": "BentoPDF",
42
+ "license": "AGPL-3.0",
43
+ "bugs": "https://github.com/alam00000/bentopdf-pymupdf-wasm/issues",
44
+ "devDependencies": {
45
+ "esbuild": "^0.21.2",
46
+ "typescript": "^5.3.3"
47
+ }
48
+ }
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Type declarations for @bentopdf/pymupdf-wasm
3
+ */
4
+
5
+ export interface PyMuPDFOptions {
6
+ assetPath?: string;
7
+ }
8
+
9
+ export interface Point { x: number; y: number; }
10
+ export interface Rect { x0: number; y0: number; x1: number; y1: number; }
11
+ export interface Color { r: number; g: number; b: number; }
12
+
13
+ export interface DocumentMetadata {
14
+ title?: string;
15
+ author?: string;
16
+ subject?: string;
17
+ keywords?: string;
18
+ creator?: string;
19
+ producer?: string;
20
+ creationDate?: string;
21
+ modDate?: string;
22
+ }
23
+
24
+ export type TextExtractionFormat = 'text' | 'blocks' | 'words' | 'dict' | 'json' | 'html' | 'xhtml' | 'xml';
25
+
26
+ export interface TextBlock {
27
+ type: 'text' | 'image';
28
+ bbox: Rect;
29
+ text?: string;
30
+ }
31
+
32
+ export interface ImageInfo {
33
+ xref: number;
34
+ width: number;
35
+ height: number;
36
+ bpc: number;
37
+ colorspace: string;
38
+ size: number;
39
+ }
40
+
41
+ export interface ExtractedImage extends ImageInfo {
42
+ data: Uint8Array;
43
+ ext: string;
44
+ }
45
+
46
+ export type AnnotationType = 'Text' | 'FreeText' | 'Line' | 'Square' | 'Circle' | 'Polygon' | 'PolyLine' | 'Highlight' | 'Underline' | 'StrikeOut' | 'Squiggly' | 'Stamp' | 'Caret' | 'Ink' | 'FileAttachment' | 'Link';
47
+
48
+ export interface AnnotationInfo {
49
+ type: AnnotationType;
50
+ rect: Rect;
51
+ content?: string;
52
+ author?: string;
53
+ color?: Color;
54
+ }
55
+
56
+ export interface FormField {
57
+ name: string;
58
+ type: 'text' | 'checkbox' | 'radio' | 'choice' | 'button' | 'signature';
59
+ value: string | boolean | string[];
60
+ rect: Rect;
61
+ readonly?: boolean;
62
+ }
63
+
64
+ export interface SearchResult {
65
+ page: number;
66
+ rect: Rect;
67
+ text: string;
68
+ }
69
+
70
+ export interface RenderOptions {
71
+ dpi?: number;
72
+ alpha?: boolean;
73
+ rotation?: number;
74
+ clip?: Rect;
75
+ }
76
+
77
+ export interface EncryptionOptions {
78
+ userPassword?: string;
79
+ ownerPassword: string;
80
+ permissions?: {
81
+ print?: boolean;
82
+ copy?: boolean;
83
+ annotate?: boolean;
84
+ modify?: boolean;
85
+ };
86
+ }
87
+
88
+ export interface LinkInfo {
89
+ rect: Rect;
90
+ uri?: string;
91
+ page?: number;
92
+ dest?: Point;
93
+ }
94
+
95
+ export interface TocEntry {
96
+ level: number;
97
+ title: string;
98
+ page: number;
99
+ dest?: Point;
100
+ }
101
+
102
+ export declare class PyMuPDFPage {
103
+ readonly pageNumber: number;
104
+ readonly rect: Rect;
105
+ readonly width: number;
106
+ readonly height: number;
107
+ readonly rotation: number;
108
+
109
+ setRotation(angle: number): void;
110
+
111
+ // Text
112
+ getText(format?: TextExtractionFormat): string | TextBlock[];
113
+ searchFor(text: string, quads?: boolean): Rect[];
114
+ insertText(point: Point, text: string, options?: { fontsize?: number; fontname?: string; color?: Color; rotate?: number }): void;
115
+
116
+ // Images
117
+ getImages(): ImageInfo[];
118
+ extractImage(xref: number): ExtractedImage | null;
119
+ insertImage(rect: Rect, imageData: Uint8Array, options?: { overlay?: boolean; keepProportion?: boolean }): void;
120
+
121
+ // Annotations
122
+ getAnnotations(): AnnotationInfo[];
123
+ addHighlight(rect: Rect, color?: Color): void;
124
+ addTextAnnotation(point: Point, text: string, icon?: string): void;
125
+ addRectAnnotation(rect: Rect, color?: Color, fill?: Color): void;
126
+ deleteAnnotations(): void;
127
+
128
+ // Links
129
+ getLinks(): LinkInfo[];
130
+ insertLink(rect: Rect, uri: string): void;
131
+
132
+ // Rendering
133
+ toImage(options?: RenderOptions): Promise<Uint8Array>;
134
+ toSvg(): string;
135
+
136
+ // Redaction
137
+ addRedaction(rect: Rect, text?: string, fill?: Color): void;
138
+ applyRedactions(): void;
139
+
140
+ // Drawing
141
+ drawLine(from: Point, to: Point, color?: Color, width?: number): void;
142
+ drawRect(rect: Rect, color?: Color, fill?: Color, width?: number): void;
143
+ drawCircle(center: Point, radius: number, color?: Color, fill?: Color): void;
144
+ }
145
+
146
+ export declare class PyMuPDFDocument {
147
+ readonly pageCount: number;
148
+ readonly isPdf: boolean;
149
+ readonly isEncrypted: boolean;
150
+ readonly needsPass: boolean;
151
+ readonly metadata: DocumentMetadata;
152
+ readonly isFormPdf: boolean;
153
+
154
+ setMetadata(metadata: Partial<DocumentMetadata>): void;
155
+
156
+ // Pages
157
+ getPage(index: number): PyMuPDFPage;
158
+ pages(): Generator<PyMuPDFPage>;
159
+ deletePage(index: number): void;
160
+ deletePages(indices: number[]): void;
161
+ insertBlankPage(index: number, width?: number, height?: number): PyMuPDFPage;
162
+ movePage(from: number, to: number): void;
163
+ copyPage(from: number, to: number): void;
164
+ selectPages(indices: number[]): void;
165
+
166
+ // Merging
167
+ insertPdf(sourceDoc: PyMuPDFDocument, options?: { fromPage?: number; toPage?: number; startAt?: number; rotate?: number }): void;
168
+
169
+ // Conversion
170
+ convertToPdf(): Uint8Array;
171
+
172
+ // Search
173
+ searchText(query: string): SearchResult[];
174
+
175
+ // TOC
176
+ getToc(): TocEntry[];
177
+ setToc(toc: TocEntry[]): void;
178
+
179
+ // Forms
180
+ getFormFields(): FormField[];
181
+ setFormField(name: string, value: string | boolean): void;
182
+
183
+ // Security
184
+ authenticate(password: string): boolean;
185
+
186
+ // Save
187
+ save(options?: { garbage?: number; deflate?: boolean; clean?: boolean; encryption?: EncryptionOptions }): Uint8Array;
188
+ saveAsBlob(options?: { garbage?: number; deflate?: boolean; clean?: boolean; encryption?: EncryptionOptions }): Blob;
189
+
190
+ close(): void;
191
+ }
192
+
193
+ export declare class PyMuPDF {
194
+ constructor(options?: PyMuPDFOptions | string);
195
+
196
+ load(): Promise<void>;
197
+
198
+ // Document operations
199
+ open(input: Blob | File): Promise<PyMuPDFDocument>;
200
+ openUrl(url: string): Promise<PyMuPDFDocument>;
201
+ create(): Promise<PyMuPDFDocument>;
202
+
203
+ // PDF2DOCX conversion
204
+ pdfToDocx(pdf: Blob | File, pages?: number[]): Promise<Blob>;
205
+
206
+ // PDF to EPUB conversion (uses Pandoc WASM)
207
+ pdfToEpub(pdf: Blob | File, options?: {
208
+ title?: string;
209
+ author?: string;
210
+ toc?: boolean;
211
+ pandocAssetPath?: string;
212
+ }): Promise<Blob>;
213
+
214
+ // Utilities
215
+ merge(pdfs: (Blob | File)[]): Promise<Blob>;
216
+ split(pdf: Blob | File, ranges: Array<{ start: number; end: number }>): Promise<Blob[]>;
217
+ extractText(pdf: Blob | File): Promise<string>;
218
+ renderPage(pdf: Blob | File, pageIndex: number, dpi?: number): Promise<Uint8Array>;
219
+
220
+ // File to PDF conversion
221
+ // Supports: XPS, EPUB, MOBI, FB2, CBZ, SVG, images (JPEG, PNG, BMP, GIF, TIFF, WEBP)
222
+ convertToPdf(file: Blob | File, options?: { filetype?: string }): Promise<Blob>;
223
+ xpsToPdf(xps: Blob | File): Promise<Blob>;
224
+ epubToPdf(epub: Blob | File): Promise<Blob>;
225
+ imageToPdf(image: Blob | File, options?: { imageType?: string }): Promise<Blob>;
226
+ svgToPdf(svg: Blob | File): Promise<Blob>;
227
+ imagesToPdf(images: (Blob | File)[]): Promise<Blob>;
228
+
229
+ // PDF to other formats
230
+ // Images: PNG, JPEG, PNM, PGM, PBM, PPM, PAM, PSD, PS
231
+ // Vector: SVG | Text: plain, HTML, XML, JSON
232
+ pdfToImages(pdf: Blob | File, options?: {
233
+ format?: 'png' | 'jpeg' | 'pnm' | 'pgm' | 'pbm' | 'ppm' | 'pam' | 'psd' | 'ps';
234
+ dpi?: number;
235
+ pages?: number[];
236
+ }): Promise<Uint8Array[]>;
237
+ pdfToSvg(pdf: Blob | File, pages?: number[]): Promise<string[]>;
238
+ pdfToText(pdf: Blob | File): Promise<string>;
239
+ pdfToHtml(pdf: Blob | File): Promise<string>;
240
+ pdfToJson(pdf: Blob | File): Promise<object[]>;
241
+ pdfToXml(pdf: Blob | File): Promise<string>;
242
+
243
+ // LLM / Markdown conversion (pymupdf4llm)
244
+ pdfToMarkdown(pdf: Blob | File, options?: {
245
+ pageBreaks?: boolean;
246
+ includeImages?: boolean;
247
+ pages?: number[];
248
+ }): Promise<string>;
249
+ pdfToLlmChunks(pdf: Blob | File): Promise<Array<{
250
+ text: string;
251
+ metadata: { page?: number; heading?: string };
252
+ }>>;
253
+
254
+ // HTML to PDF conversion - experimental
255
+ // TODO@ALAM - revisit this
256
+ // htmlToPdf(html: string, options?: {
257
+ // css?: string;
258
+ // pageSize?: 'a4' | 'letter' | 'legal' | 'a3' | 'a5';
259
+ // margins?: number | { top: number; right: number; bottom: number; left: number };
260
+ // }): Promise<Blob>;
261
+
262
+ // Text to PDF conversion
263
+ textToPdf(text: string, options?: {
264
+ fontName?: 'helv' | 'tiro' | 'cour' | 'times';
265
+ fontSize?: number;
266
+ pageSize?: 'a4' | 'letter' | 'legal' | 'a3' | 'a5';
267
+ margins?: number;
268
+ }): Promise<Blob>;
269
+ }