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", () => { ...@@ -74,14 +74,6 @@ describe("PDF insert", () => {
"2": { x: "261.6", y: "384.84" }, "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( const resultPDF = await parser.insertQrCode(
qrcode.buffer, qrcode.buffer,
"vereign.com", "vereign.com",
......
...@@ -6,10 +6,16 @@ declare type SealCoords = { ...@@ -6,10 +6,16 @@ declare type SealCoords = {
y: string; y: string;
}; };
}; };
declare global {
interface Window {
PDFNet: any;
CoreControls: any;
}
}
declare class PDFparser { declare class PDFparser {
readonly document: any; readonly document: any;
constructor(document: Buffer); constructor(document: Buffer);
getPDFMeta: () => Promise<IGetMetaResponse>; 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; export default PDFparser;
"use strict"; "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) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
...@@ -16,7 +39,6 @@ const timeUtils_1 = require("./lib/timeUtils"); ...@@ -16,7 +39,6 @@ const timeUtils_1 = require("./lib/timeUtils");
const errors_1 = require("./lib/errors"); const errors_1 = require("./lib/errors");
const generalUtils_1 = require("./lib/generalUtils"); const generalUtils_1 = require("./lib/generalUtils");
const utils_1 = require("./utils"); const utils_1 = require("./utils");
const pdfnet_node_1 = require("@pdftron/pdfnet-node");
class PDFparser { class PDFparser {
constructor(document) { constructor(document) {
this.getPDFMeta = () => __awaiter(this, void 0, void 0, function* () { this.getPDFMeta = () => __awaiter(this, void 0, void 0, function* () {
...@@ -47,16 +69,26 @@ class PDFparser { ...@@ -47,16 +69,26 @@ class PDFparser {
} }
}); });
this.insertQrCode = (imgBytes, url, coords, scaleFactor, licenseKey, certPath, certTSAUrl) => __awaiter(this, void 0, void 0, function* () { this.insertQrCode = (imgBytes, url, coords, scaleFactor, licenseKey, certPath, certTSAUrl) => __awaiter(this, void 0, void 0, function* () {
yield pdfnet_node_1.PDFNet.initialize(licenseKey); let lib, buf;
let 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 { 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) { catch (error) {
console.log(error); console.log(error);
throw new errors_1.GeneralError("Could Not sign pdf"); throw new errors_1.GeneralError("Could Not sign pdf");
} }
yield pdfnet_node_1.PDFNet.shutdown(); yield lib.shutdown();
return buf; return buf;
}); });
this.document = document; 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 ...@@ -10,14 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.TimestampAndEnableLTV = void 0; exports.TimestampAndEnableLTV = void 0;
const pdfnet_node_1 = require("@pdftron/pdfnet-node"); const TimestampAndEnableLTV = (docBuffer, certPath, certTSAUrl, imgBytes, coords, lib) => __awaiter(void 0, void 0, void 0, function* () {
const TimestampAndEnableLTV = (docBuffer, certPath, certTSAUrl, imgBytes, coords) => __awaiter(void 0, void 0, void 0, function* () { const doc = yield lib.PDFDoc.createFromBuffer(docBuffer);
const doc = yield pdfnet_node_1.PDFNet.PDFDoc.createFromBuffer(docBuffer);
doc.initSecurityHandler(); doc.initSecurityHandler();
const tst_config = yield pdfnet_node_1.PDFNet.TimestampingConfiguration.createFromURL(certTSAUrl); const tst_config = yield lib.TimestampingConfiguration.createFromURL(certTSAUrl);
const opts = yield pdfnet_node_1.PDFNet.VerificationOptions.create(pdfnet_node_1.PDFNet.VerificationOptions.SecurityLevel.e_compatibility_and_archiving); const opts = yield lib.VerificationOptions.create(lib.VerificationOptions.SecurityLevel.e_compatibility_and_archiving);
yield opts.addTrustedCertificateUString(certPath); if (typeof certPath === "string") {
const img = yield pdfnet_node_1.PDFNet.Image.createFromMemory2(doc, imgBytes); yield opts.addTrustedCertificateUString(certPath);
}
else {
yield opts.addTrustedCertificate(certPath);
}
const img = yield lib.Image.createFromMemory2(doc, imgBytes);
//make this dynamic with canvas lib //make this dynamic with canvas lib
const imgWidth = 300; const imgWidth = 300;
const imgHeight = 300; const imgHeight = 300;
...@@ -32,11 +36,11 @@ const TimestampAndEnableLTV = (docBuffer, certPath, certTSAUrl, imgBytes, coords ...@@ -32,11 +36,11 @@ const TimestampAndEnableLTV = (docBuffer, certPath, certTSAUrl, imgBytes, coords
} }
const page = yield doc.getPage(p); const page = yield doc.getPage(p);
const doctimestamp_signature_field = yield doc.createDigitalSignatureField(); 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 page.annotPushBack(widgetAnnot);
yield widgetAnnot.createSignatureAppearance(img); yield widgetAnnot.createSignatureAppearance(img);
yield doctimestamp_signature_field.timestampOnNextSave(tst_config, opts); 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; return result.buffer;
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment