The method COSDictionary.addAll(COSDictionary) creates the impression, by name and by JavaDoc comment,
that it can be used for exactly that, adding all key/value pairs from the argument dictionary to the current one, replacing old entries for the same keys.
If one looks at the implementation, though, one is in for a surprise:
Here existing Size entries explicitly are not replaced!
This appears to be a relic from times when PDFBox parsed PDF documents front to back, ignoring cross reference streams, for improved results with linearized files when merging trailer dictionaries.
Nowadays this exceptional treatment of Size does not make any sense anymore, see this stack overflow answer.
Furthermore, this method is used in other contexts than creating trailer unions, even some PDFBox methods use it to create arbitrary dictionary unions:
- org.apache.pdfbox.pdmodel.PDDocument.assignAcroFormDefaultResource(PDAcroForm, COSDictionary)
- org.apache.pdfbox.filter.JPXFilter.decode(InputStream, OutputStream, COSDictionary, int, DecodeOptions)
- org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.PDImageXObject(PDStream, PDResources)
- org.apache.pdfbox.pdmodel.graphics.image.PDInlineImage.PDInlineImage(COSDictionary, byte, PDResources)
(This list is offered by eclipse as callers of that method. There may be other, hidden calls.)
Thus, this exception should be removed after all usages of that method in PDFBox have been analyzed.