diff --git a/dist/pdfParser.js b/dist/pdfParser.js index 0cd75db12e87c42ca004686a7698c91f38578c36..6b7915b481c53e85d4d8100b5504a0719d63bb81 100644 --- a/dist/pdfParser.js +++ b/dist/pdfParser.js @@ -51,20 +51,22 @@ class PDFparser { const img = yield pdfDoc.embedPng(imgBytes); const scaled = img.scale(0.2); const pages = pdfDoc.getPages(); - const firstPage = pages[0]; - firstPage.drawImage(img, { - x: firstPage.getWidth() / 2 - scaled.width / 2, - y: firstPage.getHeight() / 2 - scaled.height / 2, - width: scaled.width, - height: 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(pdf_lib_1.PDFName.of("Annots"), pdfDoc.context.obj([link])); + for (let index = 0; index < pages.length; index++) { + const page = pages[index]; + page.drawImage(img, { + x: page.getWidth() / 2 - scaled.width / 2, + y: page.getHeight() / 2 - scaled.height / 2, + 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, + imgWidth: scaled.width, + imagHeight: scaled.height, + }); + page.node.set(pdf_lib_1.PDFName.of("Annots"), pdfDoc.context.obj([link])); + } const pdfBytes = yield pdfDoc.save(); return pdfBytes; }); diff --git a/src/pdfParser.ts b/src/pdfParser.ts index 998d662c9ab2fb0a2969fca55206bb959d35140e..f3b271bd331ab1a3326fb9cb13469cfa1ad0e2c7 100644 --- a/src/pdfParser.ts +++ b/src/pdfParser.ts @@ -52,23 +52,25 @@ class PDFparser { const pages = pdfDoc.getPages(); - const firstPage = pages[0]; + for (let index = 0; index < pages.length; index++) { + const page = pages[index]; - firstPage.drawImage(img, { - x: firstPage.getWidth() / 2 - scaled.width / 2, - y: firstPage.getHeight() / 2 - scaled.height / 2, - width: scaled.width, - height: scaled.height, - }); + page.drawImage(img, { + x: page.getWidth() / 2 - scaled.width / 2, + y: page.getHeight() / 2 - scaled.height / 2, + width: scaled.width, + height: 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, - }); + const link = this.createPageLinkAnnotation(page, url, { + imgXPos: page.getWidth() / 2 - scaled.width / 2, + imgYPos: page.getHeight() / 2 - scaled.height / 2, + imgWidth: scaled.width, + imagHeight: scaled.height, + }); - firstPage.node.set(PDFName.of("Annots"), pdfDoc.context.obj([link])); + page.node.set(PDFName.of("Annots"), pdfDoc.context.obj([link])); + } const pdfBytes = await pdfDoc.save();