How to drawImage on top-right corner of pdf page ? #1120
Unanswered
parthshah27
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
have one pdf file and one image file which is the signature of the client. I need to place the client signature image on the top right corner of every page of pdf. This whole process is in node js so I have used the pdf-lib npm package to attach image on pdf. The current issue I'm unable to place the image on the top-right corner.
Below is the logic which I used to set an image on the top-right corner of the pdf but this logic is not true for every case in some cases when the width of the image or pdf changes then it's not worked as expected. Sometimes images are getting too much small or sometimes too much large.Just because I set fix height and width. As I don't know how to calculate it dynamically
const pages = pdfDoc.getPages(); for (let i = 0; i < pdfDoc.getPageCount(); i++) { let imagePage=''; imagePage = pdfDoc.getPage(i); console.log(i+1) console.log(imagePage.getWidth()) let xx=imagePage.getWidth() console.log(imagePage.getHeight()) console.log(img.width) console.log(img.height) let yy=imagePage.getHeight() imagePage.drawImage(img, { x: xx-150, y: yy-70, width: 70, height: 70 }) }
I have put static values for height and width that not worked for all the scenarios. So can anyone help me how can i place image on top-right corner of pdf dynamically ?
Beta Was this translation helpful? Give feedback.
All reactions