diff --git a/dist/pdfParser.d.ts b/dist/pdfParser.d.ts index 6644c4a3c7eb307d99b21b5f6a6c1b8b72243b4b..6c2649943e18644c21dc34efe0df46ebd35bf896 100644 --- a/dist/pdfParser.d.ts +++ b/dist/pdfParser.d.ts @@ -1,11 +1,17 @@ /// <reference types="node" /> import { IGetMetaResponse } from "./types"; +declare type SealCoords = { + [key: string]: { + x: number; + y: number; + }; +}; declare class PDFparser { readonly document: any; readonly config: any; constructor(document: Buffer); getPDFMeta: () => Promise<IGetMetaResponse>; - insertQrCode: (imgBytes: ArrayBuffer, url: string, coords: any, scaleFactor: number) => Promise<ArrayBuffer>; + insertQrCode: (imgBytes: ArrayBuffer, url: string, coords: SealCoords, scaleFactor: number) => Promise<ArrayBuffer>; private createPageLinkAnnotation; } export default PDFparser; diff --git a/dist/pdfParser.js b/dist/pdfParser.js index 2c64a8e6c788d591a931c2d6dfcc57f94b7ee4d9..4fa7086ac692e2076603e111af0646973dcd4452 100644 --- a/dist/pdfParser.js +++ b/dist/pdfParser.js @@ -52,19 +52,15 @@ class PDFparser { 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, + x: coords[index + 1].x, + y: coords[index + 1].y, width: scaled.width, height: scaled.height, }); const link = this.createPageLinkAnnotation(page, url, { - imgXPos: page.getWidth() / 2 - scaled.width / 2, - imgYPos: page.getHeight() / 2 - scaled.height / 2, + imgXPos: coords[index + 1].x, + imgYPos: coords[index + 1].y, imgWidth: scaled.width, imagHeight: scaled.height, }); diff --git a/src/pdfParser.ts b/src/pdfParser.ts index d2433748d4ad670f64a7dc4f598f738039819483..fe1fa8fc9e71501d2b36134d004239b50ecfb61c 100644 --- a/src/pdfParser.ts +++ b/src/pdfParser.ts @@ -6,6 +6,11 @@ import { verifyPDF } from "./lib"; import { formatPdfTime } from "./lib/timeUtils"; import { AppError, GeneralError } from "./lib/errors"; import { isPDF } from "./lib/generalUtils"; + +type SealCoords = { + [key: string]: { x: number; y: number }; +}; + class PDFparser { readonly document; readonly config; @@ -50,7 +55,7 @@ class PDFparser { insertQrCode = async ( imgBytes: ArrayBuffer, url: string, - coords: any, + coords: SealCoords, scaleFactor: number ): Promise<ArrayBuffer> => { const pdfDoc = await PDFDocument.load(this.document); @@ -63,22 +68,16 @@ 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, + x: coords[index + 1].x, + y: coords[index + 1].y, width: scaled.width, height: scaled.height, }); const link = this.createPageLinkAnnotation(page, url, { - imgXPos: page.getWidth() / 2 - scaled.width / 2, - imgYPos: page.getHeight() / 2 - scaled.height / 2, + imgXPos: coords[index + 1].x, + imgYPos: coords[index + 1].y, imgWidth: scaled.width, imagHeight: scaled.height, });