"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const pdfdataextract_1 = require("pdfdataextract"); const config_1 = require("./config"); const lib_1 = require("./lib"); const timeUtils_1 = require("./lib/timeUtils"); const errors_1 = require("./lib/errors"); const generalUtils_1 = require("./lib/generalUtils"); class PDFparser { constructor(document) { this.initialize = (licenseKey) => __awaiter(this, void 0, void 0, function* () { // await PDFNet.initialize(licenseKey); }); this.getPDFMeta = () => __awaiter(this, void 0, void 0, function* () { if (!(this.document instanceof Buffer)) { throw new errors_1.AppError("Document is not Buffer"); } if (!(0, generalUtils_1.isPDF)(this.document)) { throw new errors_1.AppError("Only pdf file type is supported"); } try { const signaturesMeta = yield (0, lib_1.verifyPDF)(this.document); const pdfMeta = yield pdfdataextract_1.PdfData.extract(this.document, config_1.config); const result = { pages: pdfMeta.pages, title: pdfMeta.info.Title || "Unknown", author: pdfMeta.info.Author || "Unknown", creation_date: (0, timeUtils_1.formatPdfTime)(pdfMeta.info.CreationDate), mod_date: (0, timeUtils_1.formatPdfTime)(pdfMeta.info.ModDate), }; if (signaturesMeta) { result["signatures"] = signaturesMeta.signatures; result["expired"] = signaturesMeta.expired; } return result; } catch (error) { throw new errors_1.GeneralError(error); } }); this.document = document; } } exports.default = PDFparser;