You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I guess when you load the document again, it just generates the exact same keys for the images, and so any new images replace the previous images because they have the same key.
@rafaelgomesxyz thanks for reporting this issue and providing a clear, reproducible description! I think you're right about the recent SimpleRNG change being the cause. We want to keep using a deterministic RNG, but in order to fix this bug, we'll need to check the generated key against the existing keys in the document to prevent collisions.
What were you trying to do?
I was trying to add more images to a page in an existing document.
Why were you trying to do this?
Because I wanted to add more images.
How did you attempt to do it?
I added the new images with
PDFPage.drawImage
:What actually happened?
The new images replaced the previous images that were on the page.
What did you expect to happen?
The new images should not have replaced the previous images.
How can we reproduce the issue?
This repo contains a reproduceable example: https://github.com/rafaelgomesxyz/pdf-lib-image-bug
See the
document-1.pdf
anddocument-2.pdf
. Ondocument-2.pdf
, the first image was replaced by the second image.Version
1.17.0
What environment are you running pdf-lib in?
Node
Required Reading
Additional Notes
I'm pretty sure this happens because
SimpleRNG
is always initiated with1
(adeb734#diff-0f847354b81d20ae6094bfc27efa03e850d82939ebd49594d0c0b92b1b83be8cR71).So I guess when you load the document again, it just generates the exact same keys for the images, and so any new images replace the previous images because they have the same key.
On v1.16.0 it's working correctly, because it gets the key from here: https://github.com/Hopding/pdf-lib/blob/master/src/utils/strings.ts#L34 And in this function it correctly generates a random key every time.
The text was updated successfully, but these errors were encountered: