Hello,
we're using PDFBox to add annotations from XFDF to existing PDFs.
The basic code structure we use for this is
load the PDDocument, using PDDocument.load(File) in 2 or Loader.loadPDF(File)
in 3
construct a PDAnnotation from the XML
fetch the PDPage the annotation is supposed to show up in
add the PDAnnotation to PDPage.getAnnotations()
save the document with PDDocument.save(File)
Since we switched to 3.0.2 (from 3.0.0, we skipped 3.0.1) we encountered
several PDFs which produce an IOException when saved :
java.io.IOException: Error: Unknown type in object stream:COSObject{192, 0}
at
org.apache.pdfbox.pdfwriter.compress.COSWriterObjectStream.writeObject(COSWriterObjectStream.java:238)
~[pdfbox-app-3.0.2.jar:3.0.2]
at
org.apache.pdfbox.pdfwriter.compress.COSWriterObjectStream.writeCOSDictionary(COSWriterObjectStream.java:341)
~[pdfbox-app-3.0.2.jar:3.0.2]
at
org.apache.pdfbox.pdfwriter.compress.COSWriterObjectStream.writeObject(COSWriterObjectStream.java:230)
~[pdfbox-app-3.0.2.jar:3.0.2]
at
org.apache.pdfbox.pdfwriter.compress.COSWriterObjectStream.writeObjectsToStream(COSWriterObjectStream.java:119)
~[pdfbox-app-3.0.2.jar:3.0.2]
at
org.apache.pdfbox.pdfwriter.COSWriter.doWriteBodyCompressed(COSWriter.java:499)
~[pdfbox-app-3.0.2.jar:3.0.2]
at
org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1307)
~[pdfbox-app-3.0.2.jar:3.0.2]
at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:429)
~[pdfbox-app-3.0.2.jar:3.0.2]
at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1580)
~[pdfbox-app-3.0.2.jar:3.0.2]
at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1456)
~[pdfbox-app-3.0.2.jar:3.0.2]
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1038)
~[pdfbox-app-3.0.2.jar:3.0.2]
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:988)
~[pdfbox-app-3.0.2.jar:3.0.2]
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:944)
~[pdfbox-app-3.0.2.jar:3.0.2]
As the cross reference table of this particular (source) document only goes up
to "191 0 R" and in every observed case the reference is "+1" to the highest
reference in the document, I assume the object referred to in the exception is
the annotation we added.
This works fine when using 2.0.31 or 3.0.0 and fails only in 3.0.2 for a
particular set of PDFs.
The annotation I used to reproduce this on a local server was as simple as
<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns=http://ns.adobe.com/xfdf/ xml:space="preserve">
<annots>
<text color="#FFD100" creationdate="D:20240502085125+02'00'"
flags="print,nozoom,norotate" date="D:20240502085135+02'00'"
icon="Comment" page="0"
rect="24.331177,407.240417,48.331177,431.240417"
rotation="90" subject="Sticky Note" title="Kai.Keggenhoff">
<contents-richtext>
<body xmlns=http://www.w3.org/1999/xhtml
xmlns:xfa=http://www.xfa.org/schema/xfa-data/1.0/
xfa:APIVersion="Acrobat:24.2.0" xfa:spec="2.0.2">
<p dir="ltr"><span dir="ltr"
style="font-size:10.5pt;text-align:left;color:#000000;font-weight:normal;font-style:normal">Annotation</span></p>
</body>
</contents-richtext>
<popup flags="print,nozoom,norotate" open="no" page="0"
rect="48.331177,3414.000000,232.331177,3506.000000"/>
</text>
</annots>
</xfdf>
and is perfectly addable to a different PDF, even with using 3.0.2
So far, we only observed only one commonality between the affected PDFs, in
that were all created using "PDF24 Creator"
As the PDFs are customer data, I'm not allowed to share them so I'm looking for
suggestions how to debug this further.
One note here, is COSWriterObjectStream:238 supposed to log "object" when it
tests "base" ?!
Thanks in advance,
Kai
[cid:[email protected]]<https://thinkproject.com/de/>
Kai Keggenhoff / Senior Software Developer
thinkproject.com <https://thinkproject.com/de>
[cid:[email protected]]<https://www.linkedin.com/company/thinkproject-dach/posts/?feedView=all>[cid:[email protected]]<https://twitter.com/thinkproject_>
Read our legal information (imprint)
here<https://thinkproject.com/de/impressum/>.