n8n-nodes-pdfbro 0.1.2 → 0.1.3

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
@@ -47,3 +47,12 @@ Rotates all pages in the PDF by the specified degrees (default 90).
47
47
  ## License
48
48
 
49
49
  MIT
50
+
51
+ ## Credits & Attribution
52
+
53
+ This node powers its PDF magic using these awesome open-source libraries:
54
+
55
+ * **[pdf-lib](https://github.com/Hopding/pdf-lib)** (MIT License) - PDF creation and modification.
56
+ * **[pdf-parse](https://gitlab.com/autokent/pdf-parse)** (MIT License) - PDF text extraction.
57
+
58
+ We are grateful to the maintainers of these projects!
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nodes = void 0;
4
- const PdfUtils_node_1 = require("./nodes/PdfUtils/PdfUtils.node");
5
- exports.nodes = [PdfUtils_node_1.PdfUtils];
4
+ const PdfBro_node_1 = require("./nodes/PdfUtils/PdfBro.node");
5
+ exports.nodes = [PdfBro_node_1.PdfBro];
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PdfBro = void 0;
7
+ const pdf_lib_1 = require("pdf-lib");
8
+ // @ts-ignore
9
+ const pdf_parse_1 = __importDefault(require("pdf-parse"));
10
+ class PdfBro {
11
+ constructor() {
12
+ this.description = {
13
+ displayName: 'PdfBro',
14
+ name: 'pdfBro',
15
+ icon: 'file:pdfUtils.svg',
16
+ group: ['transform'],
17
+ version: 1,
18
+ description: 'The ultimate PDF utility (powered by pdf-lib & pdf-parse)',
19
+ defaults: {
20
+ name: 'PdfBro',
21
+ },
22
+ inputs: ['main'],
23
+ outputs: ['main'],
24
+ properties: [
25
+ {
26
+ displayName: 'Operation',
27
+ name: 'operation',
28
+ type: 'options',
29
+ noDataExpression: true,
30
+ options: [
31
+ {
32
+ name: 'Merge PDFs',
33
+ value: 'merge',
34
+ description: 'Merge multiple PDF items into a single PDF',
35
+ },
36
+ {
37
+ name: 'Split Pages',
38
+ value: 'split',
39
+ description: 'Split a PDF into separate pages',
40
+ },
41
+ {
42
+ name: 'Extract Text',
43
+ value: 'extractText',
44
+ description: 'Extract text content from PDF',
45
+ },
46
+ {
47
+ name: 'Extract Metadata',
48
+ value: 'metadata',
49
+ description: 'Get PDF metadata (title, author, pages)',
50
+ },
51
+ {
52
+ name: 'Rotate Pages',
53
+ value: 'rotate',
54
+ description: 'Rotate all pages in a PDF',
55
+ },
56
+ ],
57
+ default: 'merge',
58
+ },
59
+ {
60
+ displayName: 'Input Binary Field',
61
+ name: 'binaryPropertyName',
62
+ type: 'string',
63
+ default: 'data',
64
+ required: true,
65
+ description: 'The name of the binary field containing the PDF',
66
+ },
67
+ {
68
+ displayName: 'Rotation Degrees',
69
+ name: 'rotationDegrees',
70
+ type: 'number',
71
+ default: 90,
72
+ displayOptions: {
73
+ show: {
74
+ operation: ['rotate'],
75
+ },
76
+ },
77
+ description: 'Clockwise rotation (e.g. 90, 180, 270)',
78
+ },
79
+ ],
80
+ };
81
+ }
82
+ async execute() {
83
+ const items = this.getInputData();
84
+ const returnData = [];
85
+ const operation = this.getNodeParameter('operation', 0);
86
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
87
+ if (operation === 'merge') {
88
+ // Merge all inputs into one PDF
89
+ const mergedPdf = await pdf_lib_1.PDFDocument.create();
90
+ for (let i = 0; i < items.length; i++) {
91
+ try {
92
+ const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
93
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
94
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
95
+ const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
96
+ copiedPages.forEach((page) => mergedPdf.addPage(page));
97
+ }
98
+ catch (error) {
99
+ if (this.continueOnFail()) {
100
+ continue;
101
+ }
102
+ throw error;
103
+ }
104
+ }
105
+ const mergedPdfBuffer = await mergedPdf.save();
106
+ returnData.push({
107
+ json: { success: true, pageCount: mergedPdf.getPageCount() },
108
+ binary: {
109
+ [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(mergedPdfBuffer), 'merged.pdf', 'application/pdf'),
110
+ },
111
+ });
112
+ }
113
+ else if (operation === 'split') {
114
+ // Split each input PDF into single pages
115
+ for (let i = 0; i < items.length; i++) {
116
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
117
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
118
+ const numberOfPages = pdf.getPageCount();
119
+ for (let j = 0; j < numberOfPages; j++) {
120
+ const newPdf = await pdf_lib_1.PDFDocument.create();
121
+ const [copiedPage] = await newPdf.copyPages(pdf, [j]);
122
+ newPdf.addPage(copiedPage);
123
+ const newPdfBuffer = await newPdf.save();
124
+ returnData.push({
125
+ json: { ...items[i].json, pageNumber: j + 1, totalPages: numberOfPages },
126
+ binary: {
127
+ [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(newPdfBuffer), `page_${j + 1}.pdf`, 'application/pdf'),
128
+ },
129
+ });
130
+ }
131
+ }
132
+ }
133
+ else if (operation === 'rotate') {
134
+ const degreesVal = this.getNodeParameter('rotationDegrees', 0);
135
+ for (let i = 0; i < items.length; i++) {
136
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
137
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
138
+ const pages = pdf.getPages();
139
+ pages.forEach(page => {
140
+ const currentRotation = page.getRotation().angle;
141
+ page.setRotation((0, pdf_lib_1.degrees)(currentRotation + degreesVal));
142
+ });
143
+ const rotatedPdfBuffer = await pdf.save();
144
+ returnData.push({
145
+ json: items[i].json,
146
+ binary: {
147
+ [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(rotatedPdfBuffer), 'rotated.pdf', 'application/pdf'),
148
+ },
149
+ });
150
+ }
151
+ }
152
+ else if (operation === 'extractText') {
153
+ for (let i = 0; i < items.length; i++) {
154
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
155
+ const data = await (0, pdf_parse_1.default)(validBuffer);
156
+ returnData.push({
157
+ json: {
158
+ ...items[i].json,
159
+ text: data.text,
160
+ numpages: data.numpages,
161
+ info: data.info,
162
+ },
163
+ binary: items[i].binary,
164
+ });
165
+ }
166
+ }
167
+ else if (operation === 'metadata') {
168
+ for (let i = 0; i < items.length; i++) {
169
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
170
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
171
+ returnData.push({
172
+ json: {
173
+ ...items[i].json,
174
+ title: pdf.getTitle(),
175
+ author: pdf.getAuthor(),
176
+ subject: pdf.getSubject(),
177
+ creator: pdf.getCreator(),
178
+ producer: pdf.getProducer(),
179
+ keywords: pdf.getKeywords(),
180
+ pageCount: pdf.getPageCount(),
181
+ creationDate: pdf.getCreationDate(),
182
+ modificationDate: pdf.getModificationDate(),
183
+ },
184
+ binary: items[i].binary,
185
+ });
186
+ }
187
+ }
188
+ return [returnData];
189
+ }
190
+ }
191
+ exports.PdfBro = PdfBro;
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#ff0000" width="24px" height="24px"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-8.5 7.5c0 .83-.67 1.5-1.5 1.5H9v2H7.5V7H10c.83 0 1.5.67 1.5 1.5v1zm5 2c0 .83-.67 1.5-1.5 1.5h-2.5V7H15c.83 0 1.5.67 1.5 1.5v3zm4-3H19v1h1.5V11H19v2h-1.5V7h3v1.5zM9 9.5h1v-1H9v1zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm10 5.5h1v-3h-1v3z"/></svg>
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "n8n-nodes-pdfbro",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Offline PDF utility node for n8n",
5
5
  "keywords": [
6
6
  "n8n-community-node"
7
7
  ],
8
8
  "n8n": {
9
9
  "nodes": [
10
- "dist/nodes/PdfUtils/PdfUtils.node.js"
10
+ "dist/nodes/PdfUtils/PdfBro.node.js"
11
11
  ]
12
12
  },
13
13
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "main": "dist/index.js",
20
20
  "scripts": {
21
- "build": "tsc && copyfiles -u 1 nodes/**/*.svg dist",
21
+ "build": "tsc && copyfiles -u 1 nodes/**/*.svg dist/nodes",
22
22
  "dev": "tsc --watch"
23
23
  },
24
24
  "files": [