pdf-lib
pdf-lib copied to clipboard
pdf-lib adding non existing border to pdf
What were you trying to do?
I'm creating a pdf and adding a png with transparent background to it.
pdf-lib is adding a border to the image. This can be seen when opening the pdf in chrome both in linux and mac.
How did you attempt to do it?
const {PDFDocument} = require('pdf-lib')
const fs = require('fs/promises')
main()
.then(function () {
console.log('finished')
}, function (err) {
console.error('error', err)
})
async function main () {
const doc = await PDFDocument.create()
const buffer = await fs.readFile('./image-without-border.png')
const page = doc.addPage()
const pdfImage = await doc.embedPng(buffer)
page.drawImage(pdfImage, {
x: 0,
y: 0,
width: page.getWidth(),
height: page.getHeight()
})
const exportedPage = await doc.save()
await fs.writeFile('example.pdf', exportedPage)
}
Embedded image
Result: example.pdf
What actually happened?
The pdf shows a border in the png
What did you expect to happen?
The image that I'm attaching has no border so it should not add a border to the pdf
How can we reproduce the issue?
I've added the code in "How did you attempt" sesion.
Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
- [X] My report includes a Short, Self Contained, Correct (Compilable) Example.
- [X] I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
No response
Any luck on this? I am having similar issue - I am building my overlay - when the image has elements with a background it outlines them with a little grey line??
https://hcti.io/v1/image/566cc064-59ec-4d26-8340-09b0bbc3ec56.png Generated Ad (28).pdf