-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE caused by undefined object #177
base: trunk
Are you sure you want to change the base?
Conversation
Does this problem also occur with 2.0? Does it also occur in ordinary saving? Can you share the file? |
The issue occurred with PDFBox 3.0.0, and I haven't tested it with 2.X.X. In fact, the PDF is encrypted and doesn't allow editing. I'm sorry, but for certain reasons, I can't provide the PDF file. |
I had a look at 2.0, one of the changes isn't needed (2.0 doesn't use computeIfAbsent because it doesn't exist in the jdk, and also avoids using a null, so maybe this was introduced in refactoring), the other ones are. Your changes look useful so I'll commit them next week to give time for other opinions (COSWriter is a difficult class). I'll also add some logging. |
We have to ensure that the resulting pdf isn't (more) corrupt that the origin one if indirect object references are omitted. To remove a reference from a COSArray shouldn't be a big problem (the object reference is simply missing) but to remove a reference from a COSDictionary without removing the key will lead to a corrupt pdf In such cases the key should be removed as well or the corrupt reference should be replaced by a COSNull object |
In that case I'd really like to test this with a file. I forgot to mention yesterday that I tried to modify a PDF by "blanking" an object and then load and call saveIncremental() but no problem occured. |
I thought the issue was caused by document encryption, but after a simple test, I discovered it was not the case. The document seems to have been generated using iText 5.5.8.
perhaps the original document had already lost the obj references. maybe remove lost obj reference from a COSArray is good idea. |
https://issues.apache.org/jira/browse/PDFBOX-5717 is the same problem |
Please test whether your code works with the recent changes by @lehmi with the latest snapshot build: |
example:
see
object
3621 0 R
is not definedWhen I use
PDDocument.saveIncremental
to save the document it causes the following error:so we can skip those not define object, make it work.