drawImage not working with big rotated pdf
Author: daoshenjayCreated Nov 7, 2022Updated Sep 27, 2026
Labelsbugneeds-triage
What were you trying to do?
Hi, i want draw image to my pdf, but not working. The pdf and png image is here:
rotatedPdf.pdf

How did you attempt to do it?
my code is :
const localFilePath = '**/rotatedPdf.pdf'
const pngFilePath = '**/123456.png'
const outPath = 'your out path'
let doc
try {
doc = await PDFDocument.load(fs.readFileSync(localFilePath), { ignoreEncryption: true })
} catch (err) {
this.ctx.logger.error(err)
retrurn
}
const pageCount = doc.getPageCount()
const qrcodeBuffer = fs.readFileSync(pngFilePath)
const img = await doc.embedPng(qrcodeBuffer)
for (let i = 0; i < pageCount; i++) {
const imagePage = doc.getPage(i)
const imageWidth = 46,
imageHeight = 46
imagePage.drawImage(img, {
x: 100,
y: 100,
width: imageWidth,
height: imageHeight
})
}
const pdfBytes = await doc.save()
fs.writeFileSync(outPath,pdfBytes)What actually happened?
No images shown in PDF
What did you expect to happen?
pdf could show the image
How can we reproduce the issue?
could you please try my pdf, and tell my how could i solve this problem
Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
- My report includes a Short, Self Contained, Correct (Compilable) Example.
- I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
No response
Source: Hopding/pdf-lib