n8n-nodes-parse-pdf
Version:
Extract text, tables, and structured data from PDF files using PDF API Hub
61 lines • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParsePdf = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const parsePdf_1 = require("./actions/parsePdf");
class ParsePdf {
constructor() {
this.description = {
displayName: 'Parse PDF',
name: 'parsePdf',
icon: { light: 'file:../../icons/light.svg', dark: 'file:../../icons/dark.svg' },
group: ['transform'],
version: 1,
description: 'Extract text, tables, and structured data from PDF files using PDF API Hub',
defaults: { name: 'Parse PDF' },
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
credentials: [{ name: 'pdfapihubApi', required: true }],
usableAsTool: true,
properties: parsePdf_1.description.map(p => {
var _a;
const { displayOptions, ...rest } = p;
if ((_a = displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.show) === null || _a === void 0 ? void 0 : _a.operation) {
const { operation, ...otherShow } = displayOptions.show;
const newDisplayOptions = Object.keys(otherShow).length > 0
? { ...displayOptions, show: otherShow }
: displayOptions.hide ? { hide: displayOptions.hide } : undefined;
if (displayOptions.hide && Object.keys(otherShow).length > 0) {
return { ...rest, displayOptions: { show: otherShow, hide: displayOptions.hide } };
}
return newDisplayOptions ? { ...rest, displayOptions: newDisplayOptions } : rest;
}
return p;
}),
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
await parsePdf_1.execute.call(this, i, returnData, 'parsePdf');
}
catch (error) {
if (this.continueOnFail()) {
const message = error instanceof Error ? error.message : 'Unknown error';
returnData.push({ json: { error: message }, pairedItem: { item: i } });
}
else if (error instanceof n8n_workflow_1.NodeApiError) {
throw error;
}
else {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
}
}
}
return [returnData];
}
}
exports.ParsePdf = ParsePdf;
//# sourceMappingURL=ParsePdf.node.js.map