Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.74k stars 645 forks source link

pdf-lib adding non existing border to pdf #1510

Open furstenheim opened 1 year ago

furstenheim commented 1 year ago

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 image-without-border

Result: example.pdf

What actually happened?

The pdf shows a border in the png image

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

Additional Notes

No response

engynnadmin commented 10 months ago

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