pp-robot-module 0.2.14
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 +34 -0
- package/dist/MR/Ai.d.ts +8 -0
- package/dist/MR/Ai.js +24 -0
- package/dist/MR/Clipboard.d.ts +20 -0
- package/dist/MR/Clipboard.js +60 -0
- package/dist/MR/Csv.d.ts +20 -0
- package/dist/MR/Csv.js +56 -0
- package/dist/MR/Date.d.ts +60 -0
- package/dist/MR/Date.js +94 -0
- package/dist/MR/DbClient.d.ts +97 -0
- package/dist/MR/DbClient.js +269 -0
- package/dist/MR/Dialog.d.ts +0 -0
- package/dist/MR/Dialog.js +40 -0
- package/dist/MR/Excel.d.ts +110 -0
- package/dist/MR/Excel.js +316 -0
- package/dist/MR/File.d.ts +162 -0
- package/dist/MR/File.js +399 -0
- package/dist/MR/Hash.d.ts +12 -0
- package/dist/MR/Hash.js +21 -0
- package/dist/MR/Html.d.ts +38 -0
- package/dist/MR/Html.js +163 -0
- package/dist/MR/Http.d.ts +33 -0
- package/dist/MR/Http.js +121 -0
- package/dist/MR/Imap.d.ts +15 -0
- package/dist/MR/Imap.js +52 -0
- package/dist/MR/Ini.d.ts +31 -0
- package/dist/MR/Ini.js +55 -0
- package/dist/MR/Keyboard.d.ts +59 -0
- package/dist/MR/Keyboard.js +515 -0
- package/dist/MR/Log.d.ts +7 -0
- package/dist/MR/Log.js +52 -0
- package/dist/MR/Mouse.d.ts +51 -0
- package/dist/MR/Mouse.js +152 -0
- package/dist/MR/Net.d.ts +17 -0
- package/dist/MR/Net.js +74 -0
- package/dist/MR/Pdf.d.ts +113 -0
- package/dist/MR/Pdf.js +197 -0
- package/dist/MR/Process.d.ts +46 -0
- package/dist/MR/Process.js +106 -0
- package/dist/MR/QRcode.d.ts +13 -0
- package/dist/MR/QRcode.js +37 -0
- package/dist/MR/RedisClient.d.ts +40 -0
- package/dist/MR/RedisClient.js +183 -0
- package/dist/MR/Regex.d.ts +16 -0
- package/dist/MR/Regex.js +20 -0
- package/dist/MR/Robot.d.ts +19 -0
- package/dist/MR/Robot.js +31 -0
- package/dist/MR/Screen.d.ts +20 -0
- package/dist/MR/Screen.js +79 -0
- package/dist/MR/Smtp.d.ts +21 -0
- package/dist/MR/Smtp.js +83 -0
- package/dist/MR/String.d.ts +104 -0
- package/dist/MR/String.js +166 -0
- package/dist/MR/System.d.ts +31 -0
- package/dist/MR/System.js +201 -0
- package/dist/MR/Validator.d.ts +30 -0
- package/dist/MR/Validator.js +104 -0
- package/dist/MR/WebBrowser.d.ts +210 -0
- package/dist/MR/WebBrowser.js +484 -0
- package/dist/MR/WebBrowser2.d.ts +0 -0
- package/dist/MR/WebBrowser2.js +504 -0
- package/dist/MR/WebElement.d.ts +123 -0
- package/dist/MR/WebElement.js +172 -0
- package/dist/MR/WebKeyboard.d.ts +21 -0
- package/dist/MR/WebKeyboard.js +48 -0
- package/dist/MR/WebMouse.d.ts +46 -0
- package/dist/MR/WebMouse.js +79 -0
- package/dist/MR/Window.d.ts +8 -0
- package/dist/MR/Window.js +34 -0
- package/dist/MR/Word.d.ts +56 -0
- package/dist/MR/Word.js +220 -0
- package/dist/MR/Zip.d.ts +25 -0
- package/dist/MR/Zip.js +89 -0
- package/dist/bin/inputting-method.exe +0 -0
- package/dist/bin/keyboard-password.exe +0 -0
- package/dist/bin/lock-window.exe +0 -0
- package/dist/bin/printer-pdf.exe +0 -0
- package/dist/dotenv.d.ts +0 -0
- package/dist/dotenv.js +2 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +63 -0
- package/dist/util.d.ts +17 -0
- package/dist/util.js +41 -0
- package/package.json +120 -0
package/dist/MR/Mouse.js
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.MR = void 0;
|
13
|
+
const nut_js_1 = require("@nut-tree/nut-js");
|
14
|
+
const Log_1 = require("./Log");
|
15
|
+
var MR;
|
16
|
+
(function (MR) {
|
17
|
+
class Mouse {
|
18
|
+
constructor() { }
|
19
|
+
static setPosition(params) {
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
21
|
+
Log_1.default.debug("Mouse.setPosition", params);
|
22
|
+
const p = new nut_js_1.Point(params._x, params._y);
|
23
|
+
return yield nut_js_1.mouse.setPosition(p);
|
24
|
+
});
|
25
|
+
}
|
26
|
+
static get() {
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
28
|
+
Log_1.default.debug("Mouse.get");
|
29
|
+
return nut_js_1.mouse;
|
30
|
+
});
|
31
|
+
}
|
32
|
+
static getPosition() {
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
34
|
+
Log_1.default.debug("Mouse.getPosition", '');
|
35
|
+
return yield nut_js_1.mouse.getPosition();
|
36
|
+
});
|
37
|
+
}
|
38
|
+
static getScreenCenterPosition() {
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
40
|
+
Log_1.default.debug("Mouse.getScreenCenterPosition", '');
|
41
|
+
let h = yield nut_js_1.screen.height();
|
42
|
+
let w = yield nut_js_1.screen.width();
|
43
|
+
return Promise.resolve(new nut_js_1.Point(w / 2, h / 2));
|
44
|
+
});
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* @param params
|
48
|
+
* @returns
|
49
|
+
*/
|
50
|
+
static click(params = { _button: "left", _count: 1, _delay: 10 }) {
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
52
|
+
Log_1.default.debug("Mouse.click", params);
|
53
|
+
let BntEnum = nut_js_1.Button.LEFT;
|
54
|
+
if (params._button === "middle")
|
55
|
+
BntEnum = nut_js_1.Button.MIDDLE;
|
56
|
+
if (params._button === "right")
|
57
|
+
BntEnum = nut_js_1.Button.RIGHT;
|
58
|
+
for (let index = 0; index < params._count; index++) {
|
59
|
+
yield nut_js_1.mouse.click(BntEnum);
|
60
|
+
yield (0, nut_js_1.sleep)(params._delay);
|
61
|
+
}
|
62
|
+
});
|
63
|
+
}
|
64
|
+
static doubleClick(params = { _button: "left", _count: 1, _delay: 10 }) {
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
66
|
+
Log_1.default.debug("Mouse.doubleClick", params);
|
67
|
+
let BntEnum = nut_js_1.Button.LEFT;
|
68
|
+
if (params._button === "middle")
|
69
|
+
BntEnum = nut_js_1.Button.MIDDLE;
|
70
|
+
if (params._button === "right")
|
71
|
+
BntEnum = nut_js_1.Button.RIGHT;
|
72
|
+
for (let index = 0; index < params._count; index++) {
|
73
|
+
yield nut_js_1.mouse.doubleClick(BntEnum);
|
74
|
+
yield (0, nut_js_1.sleep)(params._delay);
|
75
|
+
}
|
76
|
+
});
|
77
|
+
}
|
78
|
+
static leftClick() {
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
80
|
+
return yield nut_js_1.mouse.click(nut_js_1.Button.LEFT);
|
81
|
+
});
|
82
|
+
}
|
83
|
+
static leftDoubleClick() {
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
85
|
+
return yield nut_js_1.mouse.doubleClick(nut_js_1.Button.LEFT);
|
86
|
+
});
|
87
|
+
}
|
88
|
+
static rightClick() {
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
90
|
+
return yield nut_js_1.mouse.click(nut_js_1.Button.RIGHT);
|
91
|
+
});
|
92
|
+
}
|
93
|
+
static drag(params) {
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
95
|
+
Log_1.default.debug("Mouse.drag", params);
|
96
|
+
return yield nut_js_1.mouse.drag((0, nut_js_1.straightTo)((0, nut_js_1.centerOf)(new nut_js_1.Region(params._x, params._y, params._width, params._height))));
|
97
|
+
});
|
98
|
+
}
|
99
|
+
static move(params) {
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
101
|
+
Log_1.default.debug("Mouse.move", params);
|
102
|
+
return yield nut_js_1.mouse.move((0, nut_js_1.straightTo)(new nut_js_1.Point(params._x, params._y)));
|
103
|
+
});
|
104
|
+
}
|
105
|
+
static scroll(params = { _direction: 'Down', _amount: 1 }) {
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
107
|
+
Log_1.default.debug("Mouse.scroll", params);
|
108
|
+
switch (params._direction) {
|
109
|
+
case "Down":
|
110
|
+
yield nut_js_1.mouse.scrollDown(params._amount);
|
111
|
+
break;
|
112
|
+
case "Up":
|
113
|
+
yield nut_js_1.mouse.scrollUp(params._amount);
|
114
|
+
break;
|
115
|
+
case "Left":
|
116
|
+
yield nut_js_1.mouse.scrollLeft(params._amount);
|
117
|
+
break;
|
118
|
+
case "Right":
|
119
|
+
yield nut_js_1.mouse.scrollRight(params._amount);
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
});
|
123
|
+
}
|
124
|
+
static moveLeft(offset) {
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
126
|
+
return yield nut_js_1.mouse.move((0, nut_js_1.left)(offset));
|
127
|
+
});
|
128
|
+
}
|
129
|
+
static moveRight(offset) {
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
131
|
+
return yield nut_js_1.mouse.move((0, nut_js_1.right)(offset));
|
132
|
+
});
|
133
|
+
}
|
134
|
+
static moveDown(offset) {
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
136
|
+
return yield nut_js_1.mouse.move((0, nut_js_1.down)(offset));
|
137
|
+
});
|
138
|
+
}
|
139
|
+
static moveUp(offset) {
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
141
|
+
return yield nut_js_1.mouse.move((0, nut_js_1.up)(offset));
|
142
|
+
});
|
143
|
+
}
|
144
|
+
static scrollLeft(offset) {
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
146
|
+
// return await mouse.scrollLeft(up(offset));
|
147
|
+
});
|
148
|
+
}
|
149
|
+
}
|
150
|
+
MR.Mouse = Mouse;
|
151
|
+
})(MR = exports.MR || (exports.MR = {}));
|
152
|
+
exports.default = MR.Mouse;
|
package/dist/MR/Net.d.ts
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
export declare namespace MR {
|
2
|
+
class Net {
|
3
|
+
private constructor();
|
4
|
+
static address(params?: {
|
5
|
+
_iface?: string;
|
6
|
+
}): Promise<any>;
|
7
|
+
static mac(): Promise<any>;
|
8
|
+
static ip4(): Promise<any>;
|
9
|
+
static ip6(): Promise<any>;
|
10
|
+
static gateway(): Promise<any>;
|
11
|
+
static checkSite(params: {
|
12
|
+
_url: string;
|
13
|
+
}): Promise<any>;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
declare const _default: typeof MR.Net;
|
17
|
+
export default _default;
|
package/dist/MR/Net.js
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.MR = void 0;
|
13
|
+
const si = require('systeminformation');
|
14
|
+
const Log_1 = require("./Log");
|
15
|
+
var MR;
|
16
|
+
(function (MR) {
|
17
|
+
class Net {
|
18
|
+
constructor() { }
|
19
|
+
static address(params) {
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
21
|
+
Log_1.default.debug("Net.address", params);
|
22
|
+
if (params === null || params === void 0 ? void 0 : params._iface) {
|
23
|
+
return yield si.networkInterfaces(params._iface);
|
24
|
+
}
|
25
|
+
return yield si.networkInterfaces('default');
|
26
|
+
});
|
27
|
+
}
|
28
|
+
/* public static async macaddress() {
|
29
|
+
return new Promise((resolve, reject) => {
|
30
|
+
address(function (err, addr) {
|
31
|
+
if (err) {
|
32
|
+
return reject(err);
|
33
|
+
}
|
34
|
+
resolve(addr);
|
35
|
+
});
|
36
|
+
});
|
37
|
+
} */
|
38
|
+
static mac() {
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
40
|
+
Log_1.default.debug("Net.mac");
|
41
|
+
const net = yield si.networkInterfaces('default');
|
42
|
+
return net.mac;
|
43
|
+
});
|
44
|
+
}
|
45
|
+
static ip4() {
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
47
|
+
Log_1.default.debug("Net.ip4");
|
48
|
+
const net = yield si.networkInterfaces('default');
|
49
|
+
return net.ip4;
|
50
|
+
});
|
51
|
+
}
|
52
|
+
static ip6() {
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
54
|
+
Log_1.default.debug("Net.ip6");
|
55
|
+
const net = yield si.networkInterfaces('default');
|
56
|
+
return net.ip6;
|
57
|
+
});
|
58
|
+
}
|
59
|
+
static gateway() {
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
61
|
+
Log_1.default.debug("Net.gateway");
|
62
|
+
return yield si.networkGatewayDefault();
|
63
|
+
});
|
64
|
+
}
|
65
|
+
static checkSite(params) {
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
67
|
+
Log_1.default.debug("Net.checkSite");
|
68
|
+
return yield si.inetChecksite(params._url);
|
69
|
+
});
|
70
|
+
}
|
71
|
+
}
|
72
|
+
MR.Net = Net;
|
73
|
+
})(MR = exports.MR || (exports.MR = {}));
|
74
|
+
exports.default = MR.Net;
|
package/dist/MR/Pdf.d.ts
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
export declare namespace MR {
|
2
|
+
class Pdf {
|
3
|
+
static text(params: {
|
4
|
+
_filename: string;
|
5
|
+
}): Promise<string>;
|
6
|
+
static json(params: {
|
7
|
+
_filename: string;
|
8
|
+
}): Promise<string>;
|
9
|
+
static create(params: {
|
10
|
+
_filename: string;
|
11
|
+
_text?: {
|
12
|
+
_str: string;
|
13
|
+
_x: number;
|
14
|
+
_y: number;
|
15
|
+
};
|
16
|
+
_comment?: {
|
17
|
+
_str: string;
|
18
|
+
_x: number;
|
19
|
+
_y: number;
|
20
|
+
};
|
21
|
+
_image?: {
|
22
|
+
_imagefile: string;
|
23
|
+
_x: number;
|
24
|
+
_y: number;
|
25
|
+
_width: number;
|
26
|
+
_height: number;
|
27
|
+
};
|
28
|
+
_rect?: {
|
29
|
+
_x: number;
|
30
|
+
_y: number;
|
31
|
+
_width: number;
|
32
|
+
_height: number;
|
33
|
+
};
|
34
|
+
}): void;
|
35
|
+
static modify(params: {
|
36
|
+
_filename: string;
|
37
|
+
_pageno: number;
|
38
|
+
_text: {
|
39
|
+
_str: string;
|
40
|
+
_x: number;
|
41
|
+
_y: number;
|
42
|
+
};
|
43
|
+
_comment: {
|
44
|
+
_str: string;
|
45
|
+
_x: number;
|
46
|
+
_y: number;
|
47
|
+
};
|
48
|
+
_image: {
|
49
|
+
_imagefile: string;
|
50
|
+
_x: number;
|
51
|
+
_y: number;
|
52
|
+
_width: number;
|
53
|
+
_height: number;
|
54
|
+
};
|
55
|
+
_rect: {
|
56
|
+
_x: number;
|
57
|
+
_y: number;
|
58
|
+
_width: number;
|
59
|
+
_height: number;
|
60
|
+
};
|
61
|
+
}): void;
|
62
|
+
static split(params: {
|
63
|
+
_filename: string;
|
64
|
+
_prefix?: string;
|
65
|
+
}): string;
|
66
|
+
structure(params: {
|
67
|
+
_filename: string;
|
68
|
+
}): Promise<void>;
|
69
|
+
static insert(params: {
|
70
|
+
_filename: string;
|
71
|
+
_insertfile: string;
|
72
|
+
_pageno: number;
|
73
|
+
}): void;
|
74
|
+
static append(params: {
|
75
|
+
_filename: string;
|
76
|
+
_appendfile: string;
|
77
|
+
}): void;
|
78
|
+
static count(params: {
|
79
|
+
_filename: string;
|
80
|
+
}): any;
|
81
|
+
static encrypt(params: {
|
82
|
+
_filename: string;
|
83
|
+
_password: string;
|
84
|
+
}): string;
|
85
|
+
static toImg(params: {
|
86
|
+
_filename: string;
|
87
|
+
}): Promise<any[]>;
|
88
|
+
static coordinate(params: {
|
89
|
+
_filename: string;
|
90
|
+
_keyword: string[];
|
91
|
+
}): Promise<{
|
92
|
+
x: number;
|
93
|
+
y: number;
|
94
|
+
kw: string;
|
95
|
+
width: number;
|
96
|
+
height: number;
|
97
|
+
pageWidth: number;
|
98
|
+
pageHeight: number;
|
99
|
+
}[]>;
|
100
|
+
static splitByRects(params: {
|
101
|
+
_filename: string;
|
102
|
+
_coordinate: {
|
103
|
+
x: number;
|
104
|
+
y: number;
|
105
|
+
width: number;
|
106
|
+
height: number;
|
107
|
+
keyword: string;
|
108
|
+
}[];
|
109
|
+
}): Promise<any[]>;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
declare const _default: typeof MR.Pdf;
|
113
|
+
export default _default;
|
package/dist/MR/Pdf.js
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.MR = void 0;
|
13
|
+
const fs = require("fs");
|
14
|
+
const path = require("path");
|
15
|
+
const Log_1 = require("./Log");
|
16
|
+
const { PDFDocument } = require('pdf-lib');
|
17
|
+
const Recipe = require("muhammara").Recipe;
|
18
|
+
const pdf_js_extract_1 = require("pdf.js-extract");
|
19
|
+
var MR;
|
20
|
+
(function (MR) {
|
21
|
+
class Pdf {
|
22
|
+
static text(params) {
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
24
|
+
Log_1.default.debug("Pdf.text", params);
|
25
|
+
return '';
|
26
|
+
});
|
27
|
+
}
|
28
|
+
static json(params) {
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
30
|
+
Log_1.default.debug("Pdf.json", params);
|
31
|
+
const pdfExtract = new pdf_js_extract_1.PDFExtract();
|
32
|
+
const options = {};
|
33
|
+
const data = yield pdfExtract.extract(params._filename, options);
|
34
|
+
return JSON.stringify(data);
|
35
|
+
});
|
36
|
+
}
|
37
|
+
static create(params) {
|
38
|
+
Log_1.default.debug("Pdf.create", params);
|
39
|
+
const pdfDoc = new Recipe("new", params._filename);
|
40
|
+
pdfDoc.createPage("letter-size");
|
41
|
+
if (params._text)
|
42
|
+
pdfDoc.text(params._text._str, params._text._x, params._text._y);
|
43
|
+
if (params._rect)
|
44
|
+
pdfDoc.rectangle(params._rect._x, params._rect._y, params._rect._width, params._rect._height);
|
45
|
+
if (params._comment)
|
46
|
+
pdfDoc.comment(params._comment._str, params._comment._x, params._comment._y);
|
47
|
+
if (params._image)
|
48
|
+
pdfDoc.image(params._image._imagefile, params._image._x, params._image._y, { width: params._image._width, height: params._image._height, keepAspectRatio: true });
|
49
|
+
pdfDoc.endPage();
|
50
|
+
// end and save
|
51
|
+
pdfDoc.endPDF();
|
52
|
+
}
|
53
|
+
static modify(params) {
|
54
|
+
Log_1.default.debug("Pdf.modify", params);
|
55
|
+
const parentPath = path.dirname(params._filename);
|
56
|
+
const fileNameWithoutExt = path.basename(params._filename, path.extname(params._filename));
|
57
|
+
const output = path.join(parentPath, fileNameWithoutExt + "-output.pdf");
|
58
|
+
const pdfDoc = new Recipe(params._filename, output);
|
59
|
+
pdfDoc.editPage(params._pageno);
|
60
|
+
if (params._text)
|
61
|
+
pdfDoc.text(params._text._str, params._text._x, params._text._y);
|
62
|
+
if (params._rect)
|
63
|
+
pdfDoc.rectangle(params._rect._x, params._rect._y, params._rect._width, params._rect._height);
|
64
|
+
if (params._comment)
|
65
|
+
pdfDoc.comment(params._comment._str, params._comment._x, params._comment._y);
|
66
|
+
if (params._image)
|
67
|
+
pdfDoc.image(params._image._imagefile, params._image._x, params._image._y, { width: params._image._width, height: params._image._height, keepAspectRatio: true });
|
68
|
+
pdfDoc.endPage();
|
69
|
+
// end and save
|
70
|
+
pdfDoc.endPDF();
|
71
|
+
}
|
72
|
+
static split(params) {
|
73
|
+
Log_1.default.debug("Pdf.split", params);
|
74
|
+
const pdfDoc = new Recipe(params._filename);
|
75
|
+
const parentPath = path.dirname(params._filename);
|
76
|
+
const outputDir = path.join(parentPath);
|
77
|
+
const fileNameWithoutExt = path.basename(params._filename, path.extname(params._filename));
|
78
|
+
let pre = params._prefix || fileNameWithoutExt;
|
79
|
+
pdfDoc.split(outputDir, pre).endPDF();
|
80
|
+
return outputDir;
|
81
|
+
}
|
82
|
+
structure(params) {
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
84
|
+
Log_1.default.debug("Pdf.structure", params);
|
85
|
+
const pdfDoc = new Recipe(params._filename);
|
86
|
+
pdfDoc.structure("pdf-structure.txt").endPDF();
|
87
|
+
});
|
88
|
+
}
|
89
|
+
static insert(params) {
|
90
|
+
Log_1.default.debug("Pdf.insert", params);
|
91
|
+
const parentPath = path.dirname(params._filename);
|
92
|
+
const fileNameWithoutExt = path.basename(params._filename, path.extname(params._filename));
|
93
|
+
const output = path.join(parentPath, fileNameWithoutExt + "-output.pdf");
|
94
|
+
const pdfDoc = new Recipe(params._filename, output);
|
95
|
+
const insertPdfDoc = new Recipe(params._insertfile);
|
96
|
+
const pages = insertPdfDoc.metadata.pages;
|
97
|
+
for (let i = 1; i <= pages; i++) {
|
98
|
+
pdfDoc.insertPage(params._pageno, params._insertfile, i);
|
99
|
+
}
|
100
|
+
pdfDoc.endPDF();
|
101
|
+
}
|
102
|
+
static append(params) {
|
103
|
+
Log_1.default.debug("Pdf.append", params);
|
104
|
+
const parentPath = path.dirname(params._filename);
|
105
|
+
const fileNameWithoutExt = path.basename(params._filename, path.extname(params._filename));
|
106
|
+
const output = path.join(parentPath, fileNameWithoutExt + "-output.pdf");
|
107
|
+
const pdfDoc = new Recipe(params._filename, output);
|
108
|
+
const insertPdfDoc = new Recipe(params._appendfile);
|
109
|
+
const pages = insertPdfDoc.metadata.pages;
|
110
|
+
for (let i = 1; i <= pages; i++) {
|
111
|
+
pdfDoc.appendPage(params._appendfile, i);
|
112
|
+
}
|
113
|
+
pdfDoc.endPDF();
|
114
|
+
}
|
115
|
+
static count(params) {
|
116
|
+
const pdfDoc = new Recipe(params._filename);
|
117
|
+
const pages = pdfDoc.metadata.pages;
|
118
|
+
return pages;
|
119
|
+
}
|
120
|
+
static encrypt(params) {
|
121
|
+
Log_1.default.debug("Pdf.encrypt", params);
|
122
|
+
const parentPath = path.dirname(params._filename);
|
123
|
+
const fileNameWithoutExt = path.basename(params._filename, path.extname(params._filename));
|
124
|
+
const output = path.join(parentPath, fileNameWithoutExt + "-output.pdf");
|
125
|
+
console.log(output);
|
126
|
+
const pdfDoc = new Recipe(params._filename, output);
|
127
|
+
pdfDoc
|
128
|
+
.encrypt({
|
129
|
+
userPassword: params._password,
|
130
|
+
ownerPassword: params._password,
|
131
|
+
userProtectionFlag: 4,
|
132
|
+
})
|
133
|
+
.endPDF();
|
134
|
+
return output;
|
135
|
+
}
|
136
|
+
static toImg(params) {
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
138
|
+
Log_1.default.debug("Pdf.toImg", params);
|
139
|
+
const output = [];
|
140
|
+
//TODO
|
141
|
+
return output;
|
142
|
+
});
|
143
|
+
}
|
144
|
+
static coordinate(params) {
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
146
|
+
Log_1.default.debug("Pdf.coordinate", params);
|
147
|
+
const pdfExtract = new pdf_js_extract_1.PDFExtract();
|
148
|
+
const options = {};
|
149
|
+
const data = yield pdfExtract.extract(params._filename, options);
|
150
|
+
//只提取第一页
|
151
|
+
const pageInfo = data.pages[0].pageInfo;
|
152
|
+
const content = data.pages[0].content;
|
153
|
+
const match = content.filter((item) => params._keyword.includes(item.str)).map((item) => ({ x: item.x, y: item.y, kw: item.str, width: item.width, height: item.height, pageWidth: pageInfo.width, pageHeight: pageInfo.height }));
|
154
|
+
return match;
|
155
|
+
});
|
156
|
+
}
|
157
|
+
static splitByRects(params) {
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
159
|
+
Log_1.default.debug("Pdf.splitByRects", params);
|
160
|
+
const coordinateList = params._coordinate;
|
161
|
+
const inputPath = params._filename;
|
162
|
+
const parentPath = path.dirname(params._filename);
|
163
|
+
const outputPath = path.join(parentPath);
|
164
|
+
const pdfBytes = fs.readFileSync(inputPath);
|
165
|
+
const pdfDoc = yield PDFDocument.load(pdfBytes);
|
166
|
+
const page = pdfDoc.getPages()[0];
|
167
|
+
if (!coordinateList || coordinateList.length <= 0) {
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
const subDocs = [];
|
171
|
+
for (let j = 0; j < coordinateList.length; j++) {
|
172
|
+
const coordinate = coordinateList[j];
|
173
|
+
const subDoc = yield PDFDocument.create();
|
174
|
+
const [subPage] = yield subDoc.copyPages(pdfDoc, [0]);
|
175
|
+
subPage.setSize(coordinate.width, coordinate.height);
|
176
|
+
subPage.setMediaBox(coordinate.x, page.getHeight() - coordinate.y - coordinate.height, coordinate.width, coordinate.height);
|
177
|
+
subPage.setCropBox(coordinate.x, page.getHeight() - coordinate.y - coordinate.height, coordinate.width, coordinate.height);
|
178
|
+
subDoc.addPage(subPage);
|
179
|
+
subDocs.push({ doc: subDoc, key: coordinate.keyword });
|
180
|
+
}
|
181
|
+
const fileNameWithoutExt = path.basename(params._filename, path.extname(params._filename));
|
182
|
+
const outputFilePaths = [];
|
183
|
+
if (subDocs.length > 0) {
|
184
|
+
for (let k = 0; k < subDocs.length; k++) {
|
185
|
+
const subPdfData = yield subDocs[k].doc.save();
|
186
|
+
const outputFilePath = path.join(outputPath, `${fileNameWithoutExt}-${subDocs[k].key}-${k + 1}.pdf`);
|
187
|
+
outputFilePaths.push(outputFilePath);
|
188
|
+
fs.writeFileSync(outputFilePath, subPdfData);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
return outputFilePaths;
|
192
|
+
});
|
193
|
+
}
|
194
|
+
}
|
195
|
+
MR.Pdf = Pdf;
|
196
|
+
})(MR = exports.MR || (exports.MR = {}));
|
197
|
+
exports.default = MR.Pdf;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
export declare namespace MR {
|
3
|
+
class Process {
|
4
|
+
private constructor();
|
5
|
+
static envs(params?: {
|
6
|
+
_type: 'Object' | 'Array';
|
7
|
+
}): NodeJS.ProcessEnv | {
|
8
|
+
name: string;
|
9
|
+
value: string;
|
10
|
+
}[];
|
11
|
+
static env(params: {
|
12
|
+
_key: string;
|
13
|
+
}): string;
|
14
|
+
static cwd(): string;
|
15
|
+
static echo(params: {
|
16
|
+
_content: string;
|
17
|
+
_newline?: boolean;
|
18
|
+
}): any;
|
19
|
+
static exec(params: {
|
20
|
+
_cmd: string;
|
21
|
+
_silent?: boolean;
|
22
|
+
}): Promise<string>;
|
23
|
+
static kill(params: {
|
24
|
+
_pid?: number;
|
25
|
+
_name?: string;
|
26
|
+
_port?: number;
|
27
|
+
}): Promise<void>;
|
28
|
+
static capture(params?: {
|
29
|
+
_filePath?: string;
|
30
|
+
_fileName?: string;
|
31
|
+
_fileType?: 'PNG' | 'JPG';
|
32
|
+
}): Promise<string>;
|
33
|
+
static captureRegion(params?: {
|
34
|
+
_x?: number;
|
35
|
+
_y?: number;
|
36
|
+
_width?: number;
|
37
|
+
_height?: number;
|
38
|
+
_filePath?: string;
|
39
|
+
_fileName?: string;
|
40
|
+
_fileType?: 'PNG' | 'JPG';
|
41
|
+
}): Promise<string>;
|
42
|
+
static test1(): Promise<void>;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
declare const _default: typeof MR.Process;
|
46
|
+
export default _default;
|