@ohos-ports/mupdf 1.28.1-beta.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/LICENSE +661 -0
- package/README.md +46 -0
- package/build/Release/mupdf_native.node +4 -0
- package/dist/index.js +34 -0
- package/dist/mupdf-native.js +177 -0
- package/dist/mupdf-wasm.d.ts +572 -0
- package/dist/mupdf-wasm.js +1 -0
- package/dist/mupdf-wasm.js.br +0 -0
- package/dist/mupdf-wasm.wasm +0 -0
- package/dist/mupdf-wasm.wasm.br +0 -0
- package/dist/mupdf.d.ts +940 -0
- package/dist/mupdf.js +3317 -0
- package/dist/mupdf.js.br +0 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# MuPDF.js
|
|
2
|
+
|
|
3
|
+
Welcome to the official MuPDF.js library from [Artifex](https://artifex.com).
|
|
4
|
+
|
|
5
|
+
Use [MuPDF](https://mupdf.com) in your JavaScript and TypeScript projects!
|
|
6
|
+
|
|
7
|
+
This library is powered by WebAssembly and can be used in all the usual
|
|
8
|
+
JavaScript environments: Node, Bun, Firefox, Safari, Chrome, etc.
|
|
9
|
+
|
|
10
|
+
## License
|
|
11
|
+
|
|
12
|
+
MuPDF.js is available under Open Source
|
|
13
|
+
[AGPL](https://www.gnu.org/licenses/agpl-3.0.html) and commercial license
|
|
14
|
+
agreements.
|
|
15
|
+
|
|
16
|
+
> If you cannot meet the requirements of the AGPL, please contact
|
|
17
|
+
> [Artifex](https://artifex.com/contact/mupdf-js) regarding a
|
|
18
|
+
> commercial license.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
npm install mupdf
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
The module is only available as an ESM module!
|
|
27
|
+
|
|
28
|
+
import mupdf from "mupdf"
|
|
29
|
+
|
|
30
|
+
var doc = mupdf.Document.openDocument("test.pdf")
|
|
31
|
+
console.log(doc.countPages())
|
|
32
|
+
|
|
33
|
+
Check out the example projects to help you get started:
|
|
34
|
+
|
|
35
|
+
- [github.com/ArtifexSoftware/mupdf/tree/master/platform/wasm/examples](https://github.com/ArtifexSoftware/mupdf/tree/master/platform/wasm/examples)
|
|
36
|
+
- [github.com/ArtifexSoftware/mupdf.js/tree/master/examples](https://github.com/ArtifexSoftware/mupdf.js/tree/master/examples)
|
|
37
|
+
|
|
38
|
+
## Documentation
|
|
39
|
+
|
|
40
|
+
- [MuPDF.js Reference](https://mupdf.readthedocs.io/en/latest/reference/javascript/)
|
|
41
|
+
- [Getting Started & Examples](https://mupdfjs.readthedocs.io/en/latest/)
|
|
42
|
+
|
|
43
|
+
## Contact
|
|
44
|
+
|
|
45
|
+
Join the Discord at [#mupdf.js](https://discord.gg/zpyAHM7XtF) to chat with the
|
|
46
|
+
developers directly.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* index.js - package entry point.
|
|
4
|
+
*
|
|
5
|
+
* Native-first dispatch: on platforms where the native MuPDF addon is
|
|
6
|
+
* available (HarmonyOS / ohos-arm64), load the N-API implementation in
|
|
7
|
+
* dist/mupdf-native.js. Otherwise fall back to the original WASM
|
|
8
|
+
* implementation in dist/mupdf.js.
|
|
9
|
+
*/
|
|
10
|
+
let impl;
|
|
11
|
+
try {
|
|
12
|
+
impl = await import("./mupdf-native.js");
|
|
13
|
+
} catch {
|
|
14
|
+
impl = await import("./mupdf.js");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Buffer = impl.Buffer;
|
|
18
|
+
export const ColorSpace = impl.ColorSpace;
|
|
19
|
+
export const Document = impl.Document;
|
|
20
|
+
export const DrawDevice = impl.DrawDevice;
|
|
21
|
+
export const Font = impl.Font;
|
|
22
|
+
export const Matrix = impl.Matrix;
|
|
23
|
+
export const Page = impl.Page;
|
|
24
|
+
export const Pixmap = impl.Pixmap;
|
|
25
|
+
export const StructuredText = impl.StructuredText;
|
|
26
|
+
export const PDFDocument = impl.PDFDocument;
|
|
27
|
+
export const PDFPage = impl.PDFPage;
|
|
28
|
+
export const PDFObject = impl.PDFObject;
|
|
29
|
+
export const Point = impl.Point;
|
|
30
|
+
export const Quad = impl.Quad;
|
|
31
|
+
export const Rectangle = impl.Rectangle;
|
|
32
|
+
export const Stream = impl.Stream;
|
|
33
|
+
|
|
34
|
+
export default impl;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* mupdf-native.js - JS API layer over the native MuPDF N-API addon
|
|
4
|
+
* (build/Release/mupdf_native.node) compiled for HarmonyOS (ohos-arm64).
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the class/method names of the official WASM-based mupdf.js API
|
|
7
|
+
* so callers can use either backend transparently.
|
|
8
|
+
*/
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const native = require("../build/Release/mupdf_native.node");
|
|
13
|
+
|
|
14
|
+
export class Matrix {
|
|
15
|
+
constructor(a = 1, b = 0, c = 0, d = 1, e = 0, f = 0) {
|
|
16
|
+
this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; this.f = f;
|
|
17
|
+
}
|
|
18
|
+
static identity() { return new Matrix(1, 0, 0, 1, 0, 0); }
|
|
19
|
+
static translate(tx, ty) { return new Matrix(1, 0, 0, 1, tx, ty); }
|
|
20
|
+
static scale(sx, sy) { return new Matrix(sx, 0, 0, sy, 0, 0); }
|
|
21
|
+
static rotate(degrees) {
|
|
22
|
+
const rad = (degrees * Math.PI) / 180;
|
|
23
|
+
const cos = Math.cos(rad), sin = Math.sin(rad);
|
|
24
|
+
return new Matrix(cos, sin, -sin, cos, 0, 0);
|
|
25
|
+
}
|
|
26
|
+
static shear(sx, sy) { return new Matrix(1, sy, sx, 1, 0, 0); }
|
|
27
|
+
multiply(m) {
|
|
28
|
+
return new Matrix(
|
|
29
|
+
this.a * m.a + this.b * m.c,
|
|
30
|
+
this.a * m.b + this.b * m.d,
|
|
31
|
+
this.c * m.a + this.d * m.c,
|
|
32
|
+
this.c * m.b + this.d * m.d,
|
|
33
|
+
this.e * m.a + this.f * m.c + m.e,
|
|
34
|
+
this.e * m.b + this.f * m.d + m.f
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class Point {
|
|
40
|
+
constructor(x = 0, y = 0) { this.x = x; this.y = y; }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Rectangle {
|
|
44
|
+
constructor(x0 = 0, y0 = 0, x1 = 0, y1 = 0) {
|
|
45
|
+
this.x0 = x0; this.y0 = y0; this.x1 = x1; this.y1 = y1;
|
|
46
|
+
}
|
|
47
|
+
get width() { return this.x1 - this.x0; }
|
|
48
|
+
get height() { return this.y1 - this.y0; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class Quad {
|
|
52
|
+
constructor(ul = { x: 0, y: 0 }, ur = { x: 0, y: 0 }, ll = { x: 0, y: 0 }, lr = { x: 0, y: 0 }) {
|
|
53
|
+
this.ul = new Point(ul.x, ul.y);
|
|
54
|
+
this.ur = new Point(ur.x, ur.y);
|
|
55
|
+
this.ll = new Point(ll.x, ll.y);
|
|
56
|
+
this.lr = new Point(lr.x, lr.y);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class Buffer extends native.MuPDFBuffer {
|
|
61
|
+
asUint8Array() { return super.asUint8Array(); }
|
|
62
|
+
asString() { return super.asString(); }
|
|
63
|
+
get length() { return super.getLength(); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class Font extends native.MuPDFFont {
|
|
67
|
+
getName() { return super.getName(); }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class ColorSpace extends native.MuPDFColorSpace {
|
|
71
|
+
getName() { return super.getName(); }
|
|
72
|
+
getNumberOfComponents() { return super.getNumberOfComponents(); }
|
|
73
|
+
}
|
|
74
|
+
ColorSpace.DeviceGray = new ColorSpace(native.getDeviceColorSpace(0));
|
|
75
|
+
ColorSpace.DeviceRGB = new ColorSpace(native.getDeviceColorSpace(1));
|
|
76
|
+
ColorSpace.DeviceBGR = new ColorSpace(native.getDeviceColorSpace(2));
|
|
77
|
+
ColorSpace.DeviceCMYK = new ColorSpace(native.getDeviceColorSpace(3));
|
|
78
|
+
ColorSpace.DeviceLab = new ColorSpace(native.getDeviceColorSpace(4));
|
|
79
|
+
|
|
80
|
+
export class Pixmap extends native.MuPDFPixmap {
|
|
81
|
+
getWidth() { return super.getWidth(); }
|
|
82
|
+
getHeight() { return super.getHeight(); }
|
|
83
|
+
getNumberOfComponents() { return super.getNumberOfComponents(); }
|
|
84
|
+
getSamples() { return super.getSamples(); }
|
|
85
|
+
asPNG() { return super.asPNG(); }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class StructuredText extends native.MuPDFStructuredText {
|
|
89
|
+
asText() { return super.asText(); }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class Page extends native.MuPDFPage {
|
|
93
|
+
toPixmap(matrix, colorspace, alpha = true) {
|
|
94
|
+
return new Pixmap(super.toPixmap(matrix, colorspace, alpha));
|
|
95
|
+
}
|
|
96
|
+
toStructuredText(options) {
|
|
97
|
+
return new StructuredText(super.toStructuredText(options));
|
|
98
|
+
}
|
|
99
|
+
search(needle, options) {
|
|
100
|
+
const hits = super.search(needle, options || {});
|
|
101
|
+
return hits.map((q) => new Quad(q.ul, q.ur, q.ll, q.lr));
|
|
102
|
+
}
|
|
103
|
+
getBounds() {
|
|
104
|
+
const b = super.getBounds();
|
|
105
|
+
return new Rectangle(b.x0, b.y0, b.x1, b.y1);
|
|
106
|
+
}
|
|
107
|
+
run(device, matrix) { return super.run(device, matrix); }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Minimal stream reader over a Buffer (readAll). */
|
|
111
|
+
export class Stream {
|
|
112
|
+
constructor(buffer) {
|
|
113
|
+
this.buffer = buffer;
|
|
114
|
+
}
|
|
115
|
+
readAll() {
|
|
116
|
+
return this.buffer.asUint8Array();
|
|
117
|
+
}
|
|
118
|
+
readAvailable() {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export class PDFObject extends native.MuPDFPDFObject {
|
|
124
|
+
toString() { return super.toString(); }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export class Document extends native.MuPDFDocument {
|
|
128
|
+
static openDocument(data, magic = "application/pdf") {
|
|
129
|
+
return new Document(native.openDocument(data, magic));
|
|
130
|
+
}
|
|
131
|
+
countPages() { return super.countPages(); }
|
|
132
|
+
loadPage(n) { return new Page(super.loadPage(n)); }
|
|
133
|
+
isPDF() { return super.isPDF(); }
|
|
134
|
+
getMetaData(key) { return super.getMetaData(key); }
|
|
135
|
+
saveToBuffer(options) { return new Buffer(super.saveToBuffer(options)); }
|
|
136
|
+
addSimpleFont(font, encoding) { return new PDFObject(super.addSimpleFont(font, encoding)); }
|
|
137
|
+
addPage(mediabox, rotate, resources, contents) {
|
|
138
|
+
return new PDFObject(super.addPage(mediabox, rotate, resources, contents));
|
|
139
|
+
}
|
|
140
|
+
insertPage(at, page) { return super.insertPage(at, page); }
|
|
141
|
+
}
|
|
142
|
+
Document.META_FORMAT = "format";
|
|
143
|
+
Document.META_ENCRYPTION = "encryption";
|
|
144
|
+
Document.META_INFO_AUTHOR = "info:Author";
|
|
145
|
+
Document.META_INFO_TITLE = "info:Title";
|
|
146
|
+
Document.META_INFO_SUBJECT = "info:Subject";
|
|
147
|
+
Document.META_INFO_KEYWORDS = "info:Keywords";
|
|
148
|
+
Document.META_INFO_CREATOR = "info:Creator";
|
|
149
|
+
Document.META_INFO_PRODUCER = "info:Producer";
|
|
150
|
+
Document.META_INFO_CREATIONDATE = "info:CreationDate";
|
|
151
|
+
Document.META_INFO_MODIFICATIONDATE = "info:ModDate";
|
|
152
|
+
|
|
153
|
+
export class PDFPage extends Page {}
|
|
154
|
+
|
|
155
|
+
export class PDFDocument extends Document {
|
|
156
|
+
constructor() {
|
|
157
|
+
super(native.createPDFDocument());
|
|
158
|
+
}
|
|
159
|
+
addSimpleFont(font, encoding) { return super.addSimpleFont(font, encoding); }
|
|
160
|
+
addPage(mediabox, rotate, resources, contents) {
|
|
161
|
+
return super.addPage(mediabox, rotate, resources, contents);
|
|
162
|
+
}
|
|
163
|
+
insertPage(at, page) { return super.insertPage(at, page); }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class DrawDevice extends native.MuPDFDrawDevice {
|
|
167
|
+
constructor(matrix, pixmap) {
|
|
168
|
+
super(matrix, pixmap);
|
|
169
|
+
}
|
|
170
|
+
close() { return super.close(); }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export default {
|
|
174
|
+
Matrix, Point, Rectangle, Quad, Buffer, Font, ColorSpace,
|
|
175
|
+
Pixmap, StructuredText, Page, PDFPage, PDFObject,
|
|
176
|
+
Document, PDFDocument, DrawDevice,
|
|
177
|
+
};
|