cantoo-scribe / pdf-lib

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

Image objects corrupted while saving/cloning an encrypted pdf #69

Open carlosrafp opened 1 week ago

carlosrafp commented 1 week ago

What were you trying to do?

The library is able to open the pdf file but after saving it corrupts some images/objects changing color.

const pdf = await PDFDocument.load(buffer, { password: '' }); const bytes = await pdf.save();

Input pdf: laudo.pdf

The output/cloned pdf displays wrong color of logo and the signature images: cloned.pdf

Checking the generated pdf on qdpf shows:

PDF Version: 1.7 File is not encrypted File is not linearized WARNING: cloned.pdf object stream 62 (object 14 0, offset 2243): unknown token while reading object; treating as string WARNING: cloned.pdf object stream 62 (object 14 0, offset 2252): unexpected ) WARNING: cloned.pdf object stream 62 (object 14 0, offset 2264): EOF while reading token WARNING: cloned.pdf object stream 62 (object 14 0, offset 8104): parse error while reading object WARNING: cloned.pdf object stream 62 (object 14 0, offset 8104): unexpected EOF WARNING: cloned.pdf object stream 62 (object 32 0, offset 7262): EOF while reading token WARNING: cloned.pdf object stream 62 (object 32 0, offset 8104): parse error while reading object WARNING: cloned.pdf object stream 62 (object 32 0, offset 8104): unexpected EOF WARNING: cloned.pdf object stream 62 (object 33 0, offset 7431): EOF while reading token WARNING: cloned.pdf object stream 62 (object 33 0, offset 8104): parse error while reading object WARNING: cloned.pdf object stream 62 (object 33 0, offset 8104): unexpected EOF WARNING: cloned.pdf object stream 62 (object 34 0, offset 7609): EOF while reading token WARNING: cloned.pdf object stream 62 (object 34 0, offset 8104): parse error while reading object WARNING: cloned.pdf object stream 62 (object 34 0, offset 8104): unexpected EOF WARNING: cloned.pdf object stream 62 (object 61 0, offset 8027): EOF while reading token WARNING: cloned.pdf object stream 62 (object 61 0, offset 8104): parse error while reading object WARNING: cloned.pdf object stream 62 (object 61 0, offset 8104): unexpected EOF qpdf: operation succeeded with warnings

How did you attempt to do it?

  1. Load the provided PDF document with an empty password option
  2. Save it

What actually happened?

Output pdf contains corrupted image objects, that displays wrong color

What did you expect to happen?

The PDF to be saved properly.

How can we reproduce the issue?

Use the steps above.

Version

2.2.3

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

No response