-
Notifications
You must be signed in to change notification settings - Fork 942
Comments
Conversation
THausherr
commented
Feb 1, 2024
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.
THausherr
commented
Feb 2, 2024
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.
lehmi
commented
Feb 3, 2024
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
THausherr
commented
Feb 3, 2024
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.
Trisia
commented
Feb 4, 2024
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.
0003719771 00000 n
0003759924 00000 n
trailer
<</Info 5 0 R/Encrypt 7894 0 R/ID [<e3d8be7479575ba4b5622d7b671d2255><64acf33dec0b965797b470cbf8346962>]/Root 75 0 R/Size 7895>>
%iText-5.5.8
startxref
3760055
%%EOF
perhaps the original document had already lost the obj references.
maybe remove lost obj reference from a COSArray is good idea.
THausherr
commented
Feb 10, 2024
https://issues.apache.org/jira/browse/PDFBOX-5717 is the same problem
THausherr
commented
Feb 12, 2024
Please test whether your code works with the recent changes by @lehmi with the latest snapshot build:
https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.2-SNAPSHOT/
example:
see
object
3621 0 Ris not definedWhen I use
PDDocument.saveIncrementalto save the document it causes the following error:so we can skip those not define object, make it work.