Broken annotations: merging annotations using PDFNet (Java) gives different results than using UI, built-in download

Product: PDFNet

Product Version: 9.4.0

Please give a brief summary of your issue:
Merging annotations using PDFNet gives different result in XFDF content than when using built-in mechanism available through PDFTron’s WebViewer (download button).

Please describe your issue and provide steps to reproduce it:
We are using PDFNet to export and merge annotations in PDF files. We have had few sessions with PDFTron’s support, but nothing has provided a solution to this issue, which becomes a critical blocker for us. Still, the annotations have different stylings or text is not visible in Acrobat Reader or MacOS’ PDF viewer, but displays correctly within PDFTron’s WebViewer.

Please provide a link to a minimal sample where the issue is reproducible:
I cannot attach PDF files (what should be supported in here), but the XFDF content follows bellow. Please, pay attention to differences in the two sets:

  1. TextColor,
  2. rect coordination adjustments,
  3. apref.

Note: title might differ, because we remove a part of the string there.

Export through PDFNet (Java) toolkit:

<?xml version="1.0" encoding=""?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
  <pdf-info xmlns="http://www.pdftron.com/pdfinfo" version="2" import-version="4"></pdf-info>
  <fields></fields>
  <annots>
    <freetext width="0" creationdate="D:20221207092640+01'00'" flags="print" date="D:20221207092710+01'00'" name="ba806959-594b-932a-5cfa-f6933bcf459b" page="0" rect="137.85,706.81,316.67,760.51" subject="Free Text" title="PRE">
      <defaultstyle>color:#E44234;font:Helvetica 12pt;text-align:left;text-vertical-align:top;</defaultstyle>
      <trn-custom-data bytes="{"trn-wrapped-text-lines":"[\"This is their FreeText, no styles \",\"(localStorage cleared) \"]"}"></trn-custom-data>
      <contents-richtext>
        <body xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:10.1.3" xfa:spec="2.0.2">
          <p>
            <span>This is their FreeText, no styles (localStorage cleared)</span>
          </p>
        </body>
      </contents-richtext>
      <defaultappearance>0 0 0 rg /Helvetica 12 Tf</defaultappearance>
      <contents>This is their FreeText, no styles (localStorage cleared)</contents>
    </freetext>
    <freetext width="0" creationdate="D:20221207092713+01'00'" flags="print" date="D:20221207092724+01'00'" name="f7abf307-1be3-1716-4d5b-ba93df02f0d2" page="0" rect="370.37,657.53,534.24,718.43" subject="Free Text" title="PRE">
      <defaultstyle>color:#E44234;font:Helvetica 12pt;text-align:left;text-vertical-align:top;</defaultstyle>
      <trn-custom-data bytes="{"trn-wrapped-text-lines":"[\"Another FreeText tool \"]"}"></trn-custom-data>
      <contents-richtext>
        <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:10.1.3" xfa:spec="2.0.2">
          <p>
            <span>Another FreeText tool</span>
          </p>
        </body>
      </contents-richtext>
      <defaultappearance>0 0 0 rg /Helvetica 12 Tf</defaultappearance>
      <contents>Another FreeText tool</contents>
    </freetext>
    <freetext callout="112.33,706.86,150.03,645.91,203.18,655.87" creationdate="D:20221207092727+01'00'" flags="print" IT="FreeTextCallout" head="OpenArrow" date="D:20221207092733+01'00'" name="1e873473-8c50-025a-30bf-7482a7eed411" page="0" fringe="91.351,0.5,0.5,36.49" rect="111.83,640.37,353.681,707.36" subject="Callout" title="PRE">
      <defaultstyle>color:#FF0000;font:Helvetica 12pt;text-align:left;text-vertical-align:top;</defaultstyle>
      <trn-custom-data bytes="{"trn-wrapped-text-lines":"[\"Callout tool \"]"}"></trn-custom-data>
      <contents-richtext>
        <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:10.1.3" xfa:spec="2.0.2">
          <p>
            <span style="color:#ff0000">Callout tool</span>
            <span></span>
          </p>
        </body>
      </contents-richtext>
      <defaultappearance>0.894 0.259 0.204 rg /Helvetica 12 Tf</defaultappearance>
      <contents>Callout tool</contents>
    </freetext>
  </annots>
  <pages>
    <defmtx matrix="1,0,0,-1,0,841.89"></defmtx>
  </pages>
</xfdf>

Export through PDFTron’s built-in utility in WebViewer (download):

<?xml version="1.0" encoding=""?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
  <pdf-info xmlns="http://www.pdftron.com/pdfinfo" version="2" import-version="4"></pdf-info>
  <fields></fields>
  <annots>
    <freetext TextColor="#E44234" width="0" creationdate="D:20221207092640+01'00'" flags="print" date="D:20221207092759+01'00'" name="ba806959-594b-932a-5cfa-f6933bcf459b" page="0" rect="137.85,706.81,316.67,760.51" subject="Free Text" title="PRE per.digre@aize.io">
      <defaultstyle>color:#E44234;font:Helvetica 12pt;text-align:left;text-vertical-align:top;</defaultstyle>
      <trn-custom-data bytes="{}"></trn-custom-data>
      <contents-richtext>
        <body xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:10.1.3" xfa:spec="2.0.2">
          <p>
            <span>This is their FreeText, no styles (localStorage cleared)</span>
          </p>
        </body>
      </contents-richtext>
      <defaultappearance>0 0 0 rg /Helvetica 12 Tf</defaultappearance>
      <contents>This is their FreeText, no styles (localStorage cleared)</contents>
      <apref y="760.51" x="137.85" gennum="0" objnum="15"></apref>
    </freetext>
    <freetext TextColor="#E44234" width="0" creationdate="D:20221207092713+01'00'" flags="print" date="D:20221207092759+01'00'" name="f7abf307-1be3-1716-4d5b-ba93df02f0d2" page="0" rect="370.37,657.53,534.24,718.43" subject="Free Text" title="PRE per.digre@aize.io">
      <defaultstyle>color:#E44234;font:Helvetica 12pt;text-align:left;text-vertical-align:top;</defaultstyle>
      <trn-custom-data bytes="{}"></trn-custom-data>
      <contents-richtext>
        <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:10.1.3" xfa:spec="2.0.2">
          <p>
            <span>Another FreeText tool</span>
          </p>
        </body>
      </contents-richtext>
      <defaultappearance>0 0 0 rg /Helvetica 12 Tf</defaultappearance>
      <contents>Another FreeText tool</contents>
      <apref y="718.43" x="370.37" gennum="0" objnum="18"></apref>
    </freetext>
    <freetext TextColor="#FF0000" callout="112.33,706.86,150.03,645.91,203.18,655.87" creationdate="D:20221207092727+01'00'" flags="print" IT="FreeTextCallout" head="OpenArrow" date="D:20221207092759+01'00'" name="1e873473-8c50-025a-30bf-7482a7eed411" page="0" fringe="91.377,0.5,0.5,36.8405" rect="111.804,640.37,353.681,707.71" subject="Callout" title="PRE per.digre@aize.io">
      <defaultstyle>color:#FF0000;font:Helvetica 12pt;text-align:left;text-vertical-align:top;</defaultstyle>
      <trn-custom-data bytes="{}"></trn-custom-data>
      <contents-richtext>
        <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:10.1.3" xfa:spec="2.0.2">
          <p>
            <span style="color:#ff0000">Callout tool</span>
            <span></span>
          </p>
        </body>
      </contents-richtext>
      <defaultappearance>0.894 0.259 0.204 rg /Helvetica 12 Tf</defaultappearance>
      <contents>Callout tool</contents>
      <apref y="707.71" x="111.804" gennum="0" objnum="20"></apref>
    </freetext>
  </annots>
  <pages>
    <defmtx matrix="1,0,0,-1,0,841.89"></defmtx>
  </pages>
</xfdf>

EDIT:

From further testing I see that TextColor element is removed from a freetext tag upon export.

Part of freetext we store before it gets merged with a PDF file:

<freetext page="0" rect="288.990,508.610,510.990,534.630" color="#FFE08F" flags="print" name="07fbf0f5-ce30-0636-21f9-3be35349997f" title="PRE lars.marthinsen@aize.io" subject="Free Text" date="D:20221208211913+01'00'" creationdate="D:20221208211907+01'00'" TextColor="#333333" FontSize="12">

Part of the same freetext after merge of annotations with the PDF file using PDFNet:

<freetext color="#FFE08F" creationdate="D:20221208211907+01'00'" flags="print" date="D:20221208211913+01'00'" name="07fbf0f5-ce30-0636-21f9-3be35349997f" page="0" rect="288.99,508.61,510.99,534.63" subject="Free Text" title="PRE">

TextColor is PDFTron specific, used as a fallback after first looking at contents-richtext or defaultStyle.

apref is an appearance reference that is PDFTron specific.

rect coordination will not impact the style or color.

We can’t guarantee the results of 3rd party viewers such as Adobe Reader or MacOS preview