@aaqu/node-red-aaqu-pdf 0.2.1 → 0.3.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 CHANGED
@@ -1,15 +1,25 @@
1
1
  ## Important Information
2
2
 
3
3
  Your support in the ongoing development of this library would be sincerely appreciated. 🙂
4
+
4
5
  [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-%23FFDD00?style=for-the-badge&logo=buymeacoffee&logoColor=black)](https://buymeacoffee.com/mazuralbert)
6
+
5
7
  # @aaqu/node-red-aaqu-pdf
6
8
 
7
- A [Node-RED](https://nodered.org/) node for extracting a single page from a PDF document.
9
+ A [Node-RED](https://nodered.org/) node for operating on a PDF document.
10
+
11
+ This module provides a custom Node-RED node that:
12
+ - get single page from pdf
13
+ - display single page in flow
8
14
 
9
- This module provides a custom Node-RED node that takes a **PDF buffer** as input and outputs a **new PDF buffer** containing only the specified page.
15
+ Get single page form pdf (file, http)
10
16
 
11
17
  ![example.png](img/example.png)
12
18
 
19
+ Display page in flow - need [node-red-contrib-image-tools](https://flows.nodered.org/node/node-red-contrib-image-tools) -> viewer
20
+
21
+ ![example2.png](img/example2.png)
22
+
13
23
  ---
14
24
 
15
25
  ## Features
@@ -18,6 +28,7 @@ This module provides a custom Node-RED node that takes a **PDF buffer** as input
18
28
  - Page number can be set either in the **node configuration** or dynamically via `msg.pdfPage`.
19
29
  - Outputs a new `Buffer` containing a PDF with only the selected page.
20
30
  - Simple integration with existing Node-RED flows.
31
+ - Convert pdf page to base64
21
32
 
22
33
  ---
23
34
 
@@ -33,36 +44,48 @@ Then restart Node-RED and the new node will appear in the editor palette.
33
44
 
34
45
  ---
35
46
 
36
- ## Usage
47
+ ## Nodes
48
+ _pdf-get-page_
37
49
 
38
- 1. Provide a PDF file (e.g., using the **file in** node).
39
- 2. Pass the PDF buffer to the **aaqu-pdf** node.
40
- 3. Configure the page number in the node’s settings, or pass it dynamically using `msg.pdfPage`.
41
- > **Note:** Page numbering starts from `1`.
42
- 4. The node will return a new PDF buffer containing only the requested page.
50
+ ![node-pdf-get-page.png](img/node-pdf-get-page.png)
51
+ - **msg.payload** - pdf buffer
52
+ - **msg.pdfPage** optional runtime override for the page number (starting at `1`).
43
53
 
44
- ### Example Flow
54
+ _pdf-to-img_
55
+
56
+ ![node-pdf-to-img.png](img/node-pdf-to-img.png)
57
+ - **msg.payload** - pdf buffer input
58
+ ---
59
+
60
+ ## Usage
61
+
62
+ _**pdf-get-page**_
45
63
 
46
64
  ```text
47
- [file in] → [aaqu-pdf] → [file out]
65
+ [pdf multi page buffer] → [pdf-get-page] → [pdf single page buffer]
48
66
  ```
49
67
 
50
68
  Where:
51
- - **file in** reads the original PDF into `msg.payload` (as a buffer).
52
- - **aaqu-pdf** extracts the configured page (or the page defined in `msg.pdfPage`).
53
- - **file out** writes the single-page PDF back to disk.
69
+ - **pdf multi page buffer** input multi page buffer.
70
+ - **pdf-get-page** extracts the configured page (or the page defined in `msg.pdfPage`) default page no 1.
71
+ - **pdf single page buffer** return single page buffer.
54
72
 
55
- ---
73
+ _**pdf-to-img**_
56
74
 
57
- ## Configuration
75
+ ```text
76
+ [pdf buffer] → [pdf-to-img] → [out base64]
77
+ ```
58
78
 
59
- - **msg.payload** - pdf buffer
60
- - **msg.pdfPage** optional runtime override for the page number (starting at `1`).
79
+ Where:
80
+ - **pdf buffer** a pdf file.
81
+ - **aaqu-pdf** extracts the page to image.
82
+ - **out base64** return image in base64 (to display use node-red-contrib-image-tools -> viewer).
61
83
 
62
84
  ---
63
85
 
64
86
  ## Use cases
65
87
 
88
+ - Fast display pdf in flow editor.
66
89
  - Extracting pages from automatically generated reports.
67
90
  - Preparing single-page documents for downstream processing.
68
91
  - Splitting large PDFs into smaller parts.
@@ -0,0 +1,96 @@
1
+ [
2
+ {
3
+ "id": "849ed833a220e0de",
4
+ "type": "http request",
5
+ "z": "19cb94d5b096ef08",
6
+ "name": "http request 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": 500,
19
+ "y": 1180,
20
+ "wires": [
21
+ [
22
+ "14a6d0b0d27a8ab9"
23
+ ]
24
+ ]
25
+ },
26
+ {
27
+ "id": "b00a362a3fa631ce",
28
+ "type": "image viewer",
29
+ "z": "19cb94d5b096ef08",
30
+ "name": "",
31
+ "width": "400",
32
+ "data": "payload",
33
+ "dataType": "msg",
34
+ "active": true,
35
+ "x": 1070,
36
+ "y": 1180,
37
+ "wires": [
38
+ []
39
+ ]
40
+ },
41
+ {
42
+ "id": "6f454b1857d84482",
43
+ "type": "inject",
44
+ "z": "19cb94d5b096ef08",
45
+ "name": "",
46
+ "props": [],
47
+ "repeat": "",
48
+ "crontab": "",
49
+ "once": false,
50
+ "onceDelay": 0.1,
51
+ "topic": "",
52
+ "x": 330,
53
+ "y": 1180,
54
+ "wires": [
55
+ [
56
+ "849ed833a220e0de"
57
+ ]
58
+ ]
59
+ },
60
+ {
61
+ "id": "14a6d0b0d27a8ab9",
62
+ "type": "pdf-get-page",
63
+ "z": "19cb94d5b096ef08",
64
+ "name": "",
65
+ "pdfPage": "3",
66
+ "x": 690,
67
+ "y": 1180,
68
+ "wires": [
69
+ [
70
+ "97821b079b898c3a"
71
+ ]
72
+ ]
73
+ },
74
+ {
75
+ "id": "97821b079b898c3a",
76
+ "type": "pdf-to-img",
77
+ "z": "19cb94d5b096ef08",
78
+ "name": "",
79
+ "x": 870,
80
+ "y": 1180,
81
+ "wires": [
82
+ [
83
+ "b00a362a3fa631ce"
84
+ ]
85
+ ]
86
+ },
87
+ {
88
+ "id": "53c5d60a126b2217",
89
+ "type": "global-config",
90
+ "env": [],
91
+ "modules": {
92
+ "node-red-contrib-image-tools": "2.1.1",
93
+ "@aaqu/node-red-aaqu-pdf": "0.3.0"
94
+ }
95
+ }
96
+ ]
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@aaqu/node-red-aaqu-pdf",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "node-red pdf creator",
5
- "main": "index.js",
5
+ "main": "pdf-get-page.js",
6
6
  "scripts": {
7
7
  "node-red": "node-red"
8
8
  },
@@ -12,16 +12,24 @@
12
12
  "node-red": {
13
13
  "version": ">=4.0.0",
14
14
  "nodes": {
15
- "pdf-get-page": "index.js"
15
+ "pdf-get-page": "pdf-get-page.js",
16
+ "pdf-to-img": "pdf-to-img.js"
16
17
  }
17
18
  },
18
- "keywords": ["node-red", "pdf", "aaqu"],
19
+ "keywords": [
20
+ "node-red",
21
+ "pdf",
22
+ "aaqu"
23
+ ],
19
24
  "author": {
20
25
  "name": "Mazur Albert",
21
- "url": "https://mazuralbert.pl"
26
+ "url": "https://mazuralbert.pl",
27
+ "email": "kontakt@mazuralbert.pl"
22
28
  },
23
29
  "dependencies": {
24
- "pdf-lib": "^1.17.1"
30
+ "canvas": "^3.2.0",
31
+ "pdf-lib": "^1.17.1",
32
+ "pdf-to-img": "^5.0.0"
25
33
  },
26
34
  "devDependencies": {
27
35
  "prettier": "^3.6.2"
@@ -0,0 +1,34 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("pdf-to-img", {
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-to-img";
14
+ },
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="pdf-to-img">
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
+
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>-->
30
+ </script>
31
+
32
+ <script type="text/html" data-help-name="pdf-to-img">
33
+ <p>A simple node that input pdf buffer and return img.</p>
34
+ </script>
package/pdf-to-img.js ADDED
@@ -0,0 +1,29 @@
1
+ const { pdf } = require("pdf-to-img");
2
+
3
+ module.exports = function (RED) {
4
+ function PDFToImageNode(config) {
5
+ RED.nodes.createNode(this, config);
6
+ // this.pdfPage = config.scale;
7
+ var node = this;
8
+ node.on("input", async function (msg) {
9
+ try {
10
+ const pdfBuffer = msg.payload;
11
+
12
+ const document = await pdf(pdfBuffer, { scale: 3 });
13
+ const page12buffer = await document.getPage(1);
14
+
15
+ msg.payload = page12buffer;
16
+ node.send(msg);
17
+ } catch (err) {
18
+ this.status({
19
+ fill: "red",
20
+ shape: "square",
21
+ text: "Error parsing PDF to Image",
22
+ });
23
+
24
+ node.error(err);
25
+ }
26
+ });
27
+ }
28
+ RED.nodes.registerType("pdf-to-img", PDFToImageNode);
29
+ };
File without changes
File without changes