@aaqu/node-red-aaqu-pdf 0.1.2 → 0.2.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.
@@ -0,0 +1,98 @@
1
+ [
2
+ {
3
+ "id": "089d17553fb029f3",
4
+ "type": "pdf-get-page",
5
+ "z": "19cb94d5b096ef08",
6
+ "name": "",
7
+ "pdfPage": "7",
8
+ "x": 710,
9
+ "y": 900,
10
+ "wires": [
11
+ [
12
+ "6e5b98ce359af5b2"
13
+ ]
14
+ ]
15
+ },
16
+ {
17
+ "id": "c53e1fd40bbfd421",
18
+ "type": "inject",
19
+ "z": "19cb94d5b096ef08",
20
+ "name": "",
21
+ "props": [],
22
+ "repeat": "",
23
+ "crontab": "",
24
+ "once": false,
25
+ "onceDelay": 0.1,
26
+ "topic": "",
27
+ "x": 250,
28
+ "y": 900,
29
+ "wires": [
30
+ [
31
+ "db7788eb72014467"
32
+ ]
33
+ ]
34
+ },
35
+ {
36
+ "id": "db7788eb72014467",
37
+ "type": "file in",
38
+ "z": "19cb94d5b096ef08",
39
+ "name": "",
40
+ "filename": "/Users/xyz/Downloads/test.pdf",
41
+ "filenameType": "str",
42
+ "format": "",
43
+ "chunk": false,
44
+ "sendError": false,
45
+ "encoding": "none",
46
+ "allProps": false,
47
+ "x": 470,
48
+ "y": 900,
49
+ "wires": [
50
+ [
51
+ "089d17553fb029f3"
52
+ ]
53
+ ]
54
+ },
55
+ {
56
+ "id": "6acc37ea7a6237e3",
57
+ "type": "debug",
58
+ "z": "19cb94d5b096ef08",
59
+ "name": "debug 3",
60
+ "active": true,
61
+ "tosidebar": true,
62
+ "console": false,
63
+ "tostatus": false,
64
+ "complete": "false",
65
+ "statusVal": "",
66
+ "statusType": "auto",
67
+ "x": 1220,
68
+ "y": 900,
69
+ "wires": []
70
+ },
71
+ {
72
+ "id": "6e5b98ce359af5b2",
73
+ "type": "file",
74
+ "z": "19cb94d5b096ef08",
75
+ "name": "",
76
+ "filename": "/Users/xyz/Downloads/test-export.pdf",
77
+ "filenameType": "str",
78
+ "appendNewline": true,
79
+ "createDir": false,
80
+ "overwriteFile": "true",
81
+ "encoding": "none",
82
+ "x": 970,
83
+ "y": 900,
84
+ "wires": [
85
+ [
86
+ "6acc37ea7a6237e3"
87
+ ]
88
+ ]
89
+ },
90
+ {
91
+ "id": "732762261c345b19",
92
+ "type": "global-config",
93
+ "env": [],
94
+ "modules": {
95
+ "@aaqu/node-red-aaqu-pdf": "0.1.3"
96
+ }
97
+ }
98
+ ]
@@ -0,0 +1,117 @@
1
+ [
2
+ {
3
+ "id": "e52a0caf922c1591",
4
+ "type": "http request",
5
+ "z": "19cb94d5b096ef08",
6
+ "name": "https://www.w3.org/2014/02/wot/slides/conway-jones.pdf",
7
+ "method": "GET",
8
+ "ret": "bin",
9
+ "paytoqs": "ignore",
10
+ "url": "https://www.w3.org/2014/02/wot/slides/conway-jones.pdf",
11
+ "tls": "",
12
+ "persist": false,
13
+ "proxy": "",
14
+ "insecureHTTPParser": false,
15
+ "authType": "",
16
+ "senderr": false,
17
+ "headers": [],
18
+ "x": 780,
19
+ "y": 1140,
20
+ "wires": [
21
+ [
22
+ "19c6eeadb3ebd712",
23
+ "b7b0060584145565"
24
+ ]
25
+ ]
26
+ },
27
+ {
28
+ "id": "add62139c712b86b",
29
+ "type": "http in",
30
+ "z": "19cb94d5b096ef08",
31
+ "name": "",
32
+ "url": "/pdf-get-single-page",
33
+ "method": "get",
34
+ "upload": false,
35
+ "skipBodyParsing": false,
36
+ "swaggerDoc": "",
37
+ "x": 390,
38
+ "y": 1140,
39
+ "wires": [
40
+ [
41
+ "e52a0caf922c1591"
42
+ ]
43
+ ]
44
+ },
45
+ {
46
+ "id": "03f1404f710d5fe9",
47
+ "type": "http response",
48
+ "z": "19cb94d5b096ef08",
49
+ "name": "",
50
+ "statusCode": "",
51
+ "headers": {
52
+ "Content-Type": "application/pdf",
53
+ "Content-Disposition": "inline; filename=a-single-pdf-page.pdf"
54
+ },
55
+ "x": 1310,
56
+ "y": 1140,
57
+ "wires": []
58
+ },
59
+ {
60
+ "id": "6d6a3cfc824f8604",
61
+ "type": "inject",
62
+ "z": "19cb94d5b096ef08",
63
+ "name": "",
64
+ "props": [],
65
+ "repeat": "",
66
+ "crontab": "",
67
+ "once": false,
68
+ "onceDelay": 0.1,
69
+ "topic": "",
70
+ "x": 450,
71
+ "y": 1200,
72
+ "wires": [
73
+ [
74
+ "e52a0caf922c1591"
75
+ ]
76
+ ]
77
+ },
78
+ {
79
+ "id": "19c6eeadb3ebd712",
80
+ "type": "debug",
81
+ "z": "19cb94d5b096ef08",
82
+ "name": "debug 7",
83
+ "active": true,
84
+ "tosidebar": true,
85
+ "console": false,
86
+ "tostatus": false,
87
+ "complete": "payload",
88
+ "targetType": "msg",
89
+ "statusVal": "",
90
+ "statusType": "auto",
91
+ "x": 1120,
92
+ "y": 1200,
93
+ "wires": []
94
+ },
95
+ {
96
+ "id": "b7b0060584145565",
97
+ "type": "pdf-get-page",
98
+ "z": "19cb94d5b096ef08",
99
+ "name": "",
100
+ "pdfPage": "4",
101
+ "x": 1130,
102
+ "y": 1140,
103
+ "wires": [
104
+ [
105
+ "03f1404f710d5fe9"
106
+ ]
107
+ ]
108
+ },
109
+ {
110
+ "id": "4e197bfa84124c08",
111
+ "type": "global-config",
112
+ "env": [],
113
+ "modules": {
114
+ "@aaqu/node-red-aaqu-pdf": "0.1.3"
115
+ }
116
+ }
117
+ ]
package/index.html CHANGED
@@ -1,33 +1,34 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('pdf-get-page',{
3
- category: 'function',
4
- color: '#a6bbcf',
5
- defaults: {
6
- name: {value:""},
7
- pdfPage: {value: 0, validate: RED.validators.number() }
8
- },
9
- inputs: 1,
10
- outputs: 1,
11
- icon: "file.svg",
12
- label: function() {
13
- return this.name||"pdf-get-page";
14
- }
15
- });
2
+ RED.nodes.registerType("pdf-get-page", {
3
+ category: "function",
4
+ color: "#a6bbcf",
5
+ defaults: {
6
+ name: { value: "" },
7
+ pdfPage: { value: 1, required: false, validate: RED.validators.number() },
8
+ },
9
+ inputs: 1,
10
+ outputs: 1,
11
+ icon: "file.svg",
12
+ label: function () {
13
+ return this.name || "pdf-get-page";
14
+ },
15
+ });
16
16
  </script>
17
17
 
18
18
  <script type="text/html" data-template-name="pdf-get-page">
19
- <div class="form-row">
20
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
21
- <input type="text" id="node-input-name" placeholder="Name">
22
- </div>
19
+ <div class="form-row">
20
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
21
+ <input type="text" id="node-input-name" placeholder="Name" />
22
+ </div>
23
23
 
24
- <div class="form-row">
25
- <label for="node-input-pdfPage"><i class="fa fa-tag"></i> Select pdf page</label>
26
- <input type="number" id="node-input-pdfPage" placeholder="Page">
27
- </div>
24
+ <div class="form-row">
25
+ <label for="node-input-pdfPage"
26
+ ><i class="fa fa-tag"></i> Select pdf page</label
27
+ >
28
+ <input type="number" id="node-input-pdfPage" placeholder="Page" />
29
+ </div>
28
30
  </script>
29
31
 
30
-
31
32
  <script type="text/html" data-help-name="pdf-get-page">
32
- <p>A simple node that input pdf buffer and return selected page in buffer.</p>
33
- </script>
33
+ <p>A simple node that input pdf buffer and return selected page in buffer.</p>
34
+ </script>
package/index.js CHANGED
@@ -6,20 +6,30 @@ module.exports = function (RED) {
6
6
  this.pdfPage = config.pdfPage;
7
7
  var node = this;
8
8
  node.on("input", async function (msg) {
9
- const pdfDoc = await pdfLib.PDFDocument.load(msg.payload);
10
- //const pages = pdfDoc.getPageCount();
11
- // console.log(pages);
9
+ try {
10
+ const pdfDoc = await pdfLib.PDFDocument.load(msg.payload);
11
+ //const pages = pdfDoc.getPageCount();
12
+ // console.log(pages);
12
13
 
13
- const newPDF = await pdfLib.PDFDocument.create();
14
+ const newPDF = await pdfLib.PDFDocument.create();
14
15
 
15
- const copiedPages = await newPDF.copyPages(pdfDoc, [node.pdfPage - 1]);
16
- const [page] = copiedPages;
16
+ const copiedPages = await newPDF.copyPages(pdfDoc, [node.pdfPage - 1]);
17
+ const [page] = copiedPages;
17
18
 
18
- newPDF.addPage(page);
19
- const pdfBytes = await newPDF.save();
19
+ newPDF.addPage(page);
20
+ const pdfBytes = await newPDF.save();
20
21
 
21
- msg.payload = Buffer.from(pdfBytes);
22
- node.send(msg);
22
+ msg.payload = Buffer.from(pdfBytes);
23
+ node.send(msg);
24
+ } catch (err) {
25
+ this.status({
26
+ fill: "red",
27
+ shape: "square",
28
+ text: "Error parsing PDF",
29
+ });
30
+
31
+ node.error(err);
32
+ }
23
33
  });
24
34
  }
25
35
  RED.nodes.registerType("pdf-get-page", PDFGetPageNode);
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@aaqu/node-red-aaqu-pdf",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "node-red pdf creator",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "node-red": "node-red"
8
8
  },
9
+ "engines": {
10
+ "node": ">=18.0.0"
11
+ },
9
12
  "node-red": {
10
13
  "version": ">=4.0.0",
11
14
  "nodes": {