diff --git a/dist/pdfParser.d.ts b/dist/pdfParser.d.ts index bac00b027c318266f0d0f57e47836440bbb247b2..cd45d469fb49e0e0184d8cce2ee97e0583a70deb 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) => Promise<ArrayBuffer>; + insertQrCode: (imgBytes: ArrayBuffer, url: string) => Promise<ArrayBuffer>; private createPageLinkAnnotation; } export default PDFparser; diff --git a/dist/pdfParser.js b/dist/pdfParser.js index 4597eec74ba88bb0298efe14d64edff649b707eb..34bec517d95182f0204cfdb047587b2827b85e6c 100644 --- a/dist/pdfParser.js +++ b/dist/pdfParser.js @@ -46,10 +46,10 @@ class PDFparser { throw new Error("Could not get pdf metadata"); } }); - this.insertQrCode = (imgBytes) => __awaiter(this, void 0, void 0, function* () { + this.insertQrCode = (imgBytes, url) => __awaiter(this, void 0, void 0, function* () { const pdfDoc = yield PDFDocument.load(this.document); const img = yield pdfDoc.embedPng(imgBytes); - const scaled = img.scale(0.5); + const scaled = img.scale(0.1); const pages = pdfDoc.getPages(); const firstPage = pages[0]; firstPage.drawImage(img, { @@ -58,7 +58,7 @@ class PDFparser { width: scaled.width, height: scaled.height, }); - const link = this.createPageLinkAnnotation(firstPage, "https://pdf-lib.js.org/", { + const link = this.createPageLinkAnnotation(firstPage, url, { imgXPos: firstPage.getWidth() / 2 - scaled.width / 2, imgYPos: firstPage.getHeight() / 2 - scaled.height / 2, imgWidth: scaled.width, diff --git a/src/pdfParser.ts b/src/pdfParser.ts index c6455e0012214fab3a0551c0116768ccc1a9ed48..fe2ad6ec6c010792fe991308fb117027d1a973a7 100644 --- a/src/pdfParser.ts +++ b/src/pdfParser.ts @@ -41,11 +41,14 @@ class PDFparser { } }; - insertQrCode = async (imgBytes: ArrayBuffer): Promise<ArrayBuffer> => { + insertQrCode = async ( + imgBytes: ArrayBuffer, + url: string + ): Promise<ArrayBuffer> => { const pdfDoc = await PDFDocument.load(this.document); const img = await pdfDoc.embedPng(imgBytes); - const scaled = img.scale(0.5); + const scaled = img.scale(0.1); const pages = pdfDoc.getPages(); @@ -58,16 +61,12 @@ class PDFparser { height: scaled.height, }); - const link = this.createPageLinkAnnotation( - firstPage, - "https://pdf-lib.js.org/", - { - imgXPos: firstPage.getWidth() / 2 - scaled.width / 2, - imgYPos: firstPage.getHeight() / 2 - scaled.height / 2, - imgWidth: scaled.width, - imagHeight: scaled.height, - } - ); + const link = this.createPageLinkAnnotation(firstPage, url, { + imgXPos: firstPage.getWidth() / 2 - scaled.width / 2, + imgYPos: firstPage.getHeight() / 2 - scaled.height / 2, + imgWidth: scaled.width, + imagHeight: scaled.height, + }); firstPage.node.set(PDFName.of("Annots"), pdfDoc.context.obj([link]));