From f752b68b7a56cf8e0bf8528e45985e4efa1fff67 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Tue, 5 Apr 2022 13:56:48 +0300 Subject: [PATCH] add dynamic coords --- dist/pdfParser.d.ts | 2 +- dist/pdfParser.js | 6 +++++- src/pdfParser.ts | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dist/pdfParser.d.ts b/dist/pdfParser.d.ts index 05d9f6f..6644c4a 100644 --- a/dist/pdfParser.d.ts +++ b/dist/pdfParser.d.ts @@ -5,7 +5,7 @@ declare class PDFparser { readonly config: any; constructor(document: Buffer); getPDFMeta: () => Promise<IGetMetaResponse>; - insertQrCode: (imgBytes: ArrayBuffer, url: string, scaleFactor: number) => Promise<ArrayBuffer>; + insertQrCode: (imgBytes: ArrayBuffer, url: string, coords: any, scaleFactor: number) => Promise<ArrayBuffer>; private createPageLinkAnnotation; } export default PDFparser; diff --git a/dist/pdfParser.js b/dist/pdfParser.js index 94d4530..2c64a8e 100644 --- a/dist/pdfParser.js +++ b/dist/pdfParser.js @@ -45,13 +45,17 @@ class PDFparser { throw new errors_1.GeneralError(error); } }); - this.insertQrCode = (imgBytes, url, scaleFactor) => __awaiter(this, void 0, void 0, function* () { + this.insertQrCode = (imgBytes, url, coords, scaleFactor) => __awaiter(this, void 0, void 0, function* () { const pdfDoc = yield pdf_lib_1.PDFDocument.load(this.document); const img = yield pdfDoc.embedPng(imgBytes); const scaled = img.scale(scaleFactor); const pages = pdfDoc.getPages(); for (let index = 0; index < pages.length; index++) { const page = pages[index]; + console.log("dynamic x ", coords[index + 1].x); + console.log("dynamic y ", coords[index + 1].y); + console.log("x", page.getWidth() / 2 - scaled.width / 2); + console.log("y", page.getHeight() / 2 - scaled.height / 2); page.drawImage(img, { x: page.getWidth() / 2 - scaled.width / 2, y: page.getHeight() / 2 - scaled.height / 2, diff --git a/src/pdfParser.ts b/src/pdfParser.ts index 0729fa8..d243374 100644 --- a/src/pdfParser.ts +++ b/src/pdfParser.ts @@ -50,6 +50,7 @@ class PDFparser { insertQrCode = async ( imgBytes: ArrayBuffer, url: string, + coords: any, scaleFactor: number ): Promise<ArrayBuffer> => { const pdfDoc = await PDFDocument.load(this.document); @@ -62,6 +63,12 @@ class PDFparser { for (let index = 0; index < pages.length; index++) { const page = pages[index]; + console.log("dynamic x ", coords[index + 1].x); + console.log("dynamic y ", coords[index + 1].y); + + console.log("x", page.getWidth() / 2 - scaled.width / 2); + console.log("y", page.getHeight() / 2 - scaled.height / 2); + page.drawImage(img, { x: page.getWidth() / 2 - scaled.width / 2, y: page.getHeight() / 2 - scaled.height / 2, -- GitLab