diff --git a/dist/pdfParser.js b/dist/pdfParser.js index 87278fd1b612ac43c3287c4279dad21b61844baf..6a76d7a6e9a5cec9ba958cf80440a4d96079b86f 100644 --- a/dist/pdfParser.js +++ b/dist/pdfParser.js @@ -48,13 +48,22 @@ class PDFparser { this.insertQrCode = (imgBytes) => __awaiter(this, void 0, void 0, function* () { const pdfDoc = yield PDFDocument.load(this.document); const img = yield pdfDoc.embedPng(imgBytes); - const imagePage = pdfDoc.insertPage(0); - imagePage.drawImage(img, { - x: 0, - y: 0, - width: imagePage.getWidth(), - height: imagePage.getHeight(), + // const imagePage = pdfDoc.insertPage(0); + const pages = pdfDoc.getPages(); + const firstPage = pages[0]; + const { width, height } = firstPage.getSize(); + firstPage.drawImage(img, { + x: firstPage.getWidth() / 2 - img.width / 2, + y: firstPage.getHeight() / 2 - img.height / 2, + width: img.width, + height: img.height, }); + // firstPage.drawImage(img, { + // x: 0, + // y: 0, + // width: firstPage.getWidth(), + // height: firstPage.getHeight(), + // }); const pdfBytes = yield pdfDoc.save(); return pdfBytes; }); diff --git a/src/pdfParser.ts b/src/pdfParser.ts index 15465b3e6154c26e219736b070bc8167d361028c..bca307461a0d684ec1f2dd8f3bd7e2fadddfe983 100644 --- a/src/pdfParser.ts +++ b/src/pdfParser.ts @@ -44,15 +44,27 @@ class PDFparser { insertQrCode = async (imgBytes: ArrayBuffer): Promise<ArrayBuffer> => { const pdfDoc = await PDFDocument.load(this.document); const img = await pdfDoc.embedPng(imgBytes); - const imagePage = pdfDoc.insertPage(0); + // const imagePage = pdfDoc.insertPage(0); - imagePage.drawImage(img, { - x: 0, - y: 0, - width: imagePage.getWidth(), - height: imagePage.getHeight(), + const pages = pdfDoc.getPages(); + const firstPage = pages[0]; + + const { width, height } = firstPage.getSize(); + + firstPage.drawImage(img, { + x: firstPage.getWidth() / 2 - img.width / 2, + y: firstPage.getHeight() / 2 - img.height / 2, + width: img.width, + height: img.height, }); + // firstPage.drawImage(img, { + // x: 0, + // y: 0, + // width: firstPage.getWidth(), + // height: firstPage.getHeight(), + // }); + const pdfBytes = await pdfDoc.save(); return pdfBytes;