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

Hope to deal with too much warning of "Trying to parse invalid object" #40

Closed mjzcng closed 7 months ago

mjzcng commented 9 months ago

Describe your idea

I am proposing the addition of a parameter to control the warning output behavior of the program.

How could this be implemented?

This can be implemented in the file pdf-lib/src/core/parser/PDFParser.ts within the function tryToParseInvalidIndirectObject. By adding a parameter check around line 200's console.warn(msg); and line 204's console.warn(\Invalid object ref: ${ref}`);`, we can control whether or not these warnings are outputted.

What problem are you trying to solve?

While using the pdf-lib library to parse large PDF files, particularly when dealing with some encrypted PDFs that cannot be parsed properly, there is an excessive number of "Trying to parse invalid object" warning messages. In my case, over 10,000 such messages were generated from a single load() call.

Why does this matter to you?

The flood of warning messages greatly affects the log analysis of the overall program, as well as its performance.

Would others find this helpful?

I have noticed that there are several similar issues mentioned in the Hopding/pdf-lib issue tracker.

Are you interested in implementing your proposal?

No

Why are you submitting a proposal?

I believe this problem can be resolved easily and that it would help many people.

Additional Notes

No response

Sharcoux commented 8 months ago

We'll consider this. Ideally, I think that we could try to sum up all the warnings of the same type in a single warning message.

Sharcoux commented 7 months ago

Released in 1.20.3

You can use the warnOnInvalidObjects prop to enable the warnings. Default value will be "false".