Apologies, the mailing list obviously likes eating HTML entities, so some parts may seem strange. For clarification : when a freetext annotations contains an (ampersand character), this is encoded as the (ampersand entity) in the XFDF submitted by Adobe Reader. When I merge the XFDF with a PDF, the annotation is displayed incorrectly, unless I replace "(ampersand entity)" with "(ampersand entity)amp;" in the XFDF before merging. The sample XFDF in the code was likely invalidated by posting too and needs its (ampersand characters) replaced with corresponding (ampersand entities).
On 2016-12-16 09:54 (+0100), Kai Keggenhoff <[email protected]> wrote: > Hello,> > > I'm experiencing a problem when I'm merging PDFs with freetext annotations > read from XFDF strings.> > Whenever there's a "freetext" annotation with a "&" in the text (submitted as > "&" by Adobe Reader in the XFDF), merging this annotation will lead to a > corrupted display in the resulting PDF.> > This corruption manifests itself in the way that instead of the actual text, > it shows "<body ..." from the XML.> > > However, if I crudely replace the "&" with "&amp;" in the XFDF prior > to merging, the annotation is displayed correctly.> > I have tried to read the XFDF via FDFDocument.loadXFDF(new > ByteArrayInputStream(xfdf.getBytes("UTF-8"))) instead of parsing it to a > document, but this did not change anything.> > > Tested against PDFBox 2.0.3 and 2.0.4 as of this morning.> > > My sample code is at the end of the mail, for the input file "demo.pdf" any > portrait A4/letter format PDF should work.> > > Kind regards,> > > Kai Keggenhoff> > > > > > > import java.io.File;> > import java.io.StringReader;> > import java.util.List;> > import javax.xml.parsers.*;> > import javax.xml.transform.*;> > import javax.xml.transform.dom.

