Skip to content
Snippets Groups Projects
Commit bb95c5e3 authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

build

parent af550e03
No related branches found
No related tags found
No related merge requests found
......@@ -74,14 +74,6 @@ describe("PDF insert", () => {
"2": { x: "261.6", y: "384.84" },
};
// imgBytes: ArrayBuffer,
// url: string,
// coords: SealCoords,
// scaleFactor: number,
// licenseKey: string,
// certPath: string,
// certTSAUrl: string
const resultPDF = await parser.insertQrCode(
qrcode.buffer,
"vereign.com",
......
......@@ -6,10 +6,16 @@ declare type SealCoords = {
y: string;
};
};
declare global {
interface Window {
PDFNet: any;
CoreControls: any;
}
}
declare class PDFparser {
readonly document: any;
constructor(document: Buffer);
getPDFMeta: () => Promise<IGetMetaResponse>;
insertQrCode: (imgBytes: ArrayBuffer, url: string, coords: SealCoords, scaleFactor: number, licenseKey: string, certPath: string, certTSAUrl: string) => Promise<ArrayBuffer>;
insertQrCode: (imgBytes: ArrayBuffer, url: string, coords: SealCoords, scaleFactor: number, licenseKey: string, certPath: string | ArrayBuffer, certTSAUrl: string) => Promise<ArrayBuffer>;
}
export default PDFparser;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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) {
......@@ -16,7 +39,6 @@ const timeUtils_1 = require("./lib/timeUtils");
const errors_1 = require("./lib/errors");
const generalUtils_1 = require("./lib/generalUtils");
const utils_1 = require("./utils");
const pdfnet_node_1 = require("@pdftron/pdfnet-node");
class PDFparser {
constructor(document) {
this.getPDFMeta = () => __awaiter(this, void 0, void 0, function* () {
......@@ -47,16 +69,26 @@ class PDFparser {
}
});
this.insertQrCode = (imgBytes, url, coords, scaleFactor, licenseKey, certPath, certTSAUrl) => __awaiter(this, void 0, void 0, function* () {
yield pdfnet_node_1.PDFNet.initialize(licenseKey);
let buf;
let lib, buf;
if (typeof window !== `undefined`) {
lib = window.PDFNet;
const CoreControls = window.CoreControls;
CoreControls.setWorkerPath("webviewer/core");
}
else {
const pdflib = yield Promise.resolve().then(() => __importStar(require("@pdftron/pdfnet-node")));
lib = pdflib.PDFNet;
}
//will this work ??
yield lib.initialize(licenseKey);
try {
buf = yield (0, utils_1.TimestampAndEnableLTV)(this.document, certPath, certTSAUrl, imgBytes, coords);
buf = yield (0, utils_1.TimestampAndEnableLTV)(this.document, certPath, certTSAUrl, imgBytes, coords, lib);
}
catch (error) {
console.log(error);
throw new errors_1.GeneralError("Could Not sign pdf");
}
yield pdfnet_node_1.PDFNet.shutdown();
yield lib.shutdown();
return buf;
});
this.document = document;
......
export declare const TimestampAndEnableLTV: (docBuffer: ArrayBuffer, certPath: string, certTSAUrl: string, imgBytes: ArrayBuffer, coords: any) => Promise<ArrayBuffer>;
export declare const TimestampAndEnableLTV: (docBuffer: ArrayBuffer, certPath: string | ArrayBuffer, certTSAUrl: string, imgBytes: ArrayBuffer, coords: any, lib: any) => Promise<ArrayBuffer>;
......@@ -10,14 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimestampAndEnableLTV = void 0;
const pdfnet_node_1 = require("@pdftron/pdfnet-node");
const TimestampAndEnableLTV = (docBuffer, certPath, certTSAUrl, imgBytes, coords) => __awaiter(void 0, void 0, void 0, function* () {
const doc = yield pdfnet_node_1.PDFNet.PDFDoc.createFromBuffer(docBuffer);
const TimestampAndEnableLTV = (docBuffer, certPath, certTSAUrl, imgBytes, coords, lib) => __awaiter(void 0, void 0, void 0, function* () {
const doc = yield lib.PDFDoc.createFromBuffer(docBuffer);
doc.initSecurityHandler();
const tst_config = yield pdfnet_node_1.PDFNet.TimestampingConfiguration.createFromURL(certTSAUrl);
const opts = yield pdfnet_node_1.PDFNet.VerificationOptions.create(pdfnet_node_1.PDFNet.VerificationOptions.SecurityLevel.e_compatibility_and_archiving);
yield opts.addTrustedCertificateUString(certPath);
const img = yield pdfnet_node_1.PDFNet.Image.createFromMemory2(doc, imgBytes);
const tst_config = yield lib.TimestampingConfiguration.createFromURL(certTSAUrl);
const opts = yield lib.VerificationOptions.create(lib.VerificationOptions.SecurityLevel.e_compatibility_and_archiving);
if (typeof certPath === "string") {
yield opts.addTrustedCertificateUString(certPath);
}
else {
yield opts.addTrustedCertificate(certPath);
}
const img = yield lib.Image.createFromMemory2(doc, imgBytes);
//make this dynamic with canvas lib
const imgWidth = 300;
const imgHeight = 300;
......@@ -32,11 +36,11 @@ const TimestampAndEnableLTV = (docBuffer, certPath, certTSAUrl, imgBytes, coords
}
const page = yield doc.getPage(p);
const doctimestamp_signature_field = yield doc.createDigitalSignatureField();
const widgetAnnot = yield pdfnet_node_1.PDFNet.SignatureWidget.createWithDigitalSignatureField(doc, new pdfnet_node_1.PDFNet.Rect(parseFloat(coords[p].x), parseFloat(coords[p].x + imgWidth), parseFloat(coords[p].y), parseFloat(coords[p].y + imgHeight)), doctimestamp_signature_field);
const widgetAnnot = yield lib.SignatureWidget.createWithDigitalSignatureField(doc, new lib.Rect(parseFloat(coords[p].x), parseFloat(coords[p].x + imgWidth), parseFloat(coords[p].y), parseFloat(coords[p].y + imgHeight)), doctimestamp_signature_field);
yield page.annotPushBack(widgetAnnot);
yield widgetAnnot.createSignatureAppearance(img);
yield doctimestamp_signature_field.timestampOnNextSave(tst_config, opts);
result = yield doc.saveMemoryBuffer(pdfnet_node_1.PDFNet.SDFDoc.SaveOptions.e_incremental);
result = yield doc.saveMemoryBuffer(lib.SDFDoc.SaveOptions.e_incremental);
}
return result.buffer;
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment