Annotation - MergeXFDF does not include the rotation of free text in .NET Framework

WebViewer Version: 10.0.1
SDK .NET 4.5.1+ Version: 2.0.0 (10.0.0)

So Recently I am trying to do the following:

  1. Use WebViewer SDK (JavaScript) to show the WebViewer on a web page for user to do some annotation
  2. Add A custom button to export the XFDF string:
//JavaScript
const { documentViewer, annotationManager } = instance.Core;
const xfdfString = await annotationManager.exportAnnotationCommand(); //or exportAnnotations(), depending on what approach next step is using
//pass the xfdfString to next step(AJAX)
  1. Using .NET Framework SDK to collect the XFDF string, merging the XFDF and the PDF file:
//C#
using (PDFDoc doc = new PDFDoc(stream))
{
    var option = new MergeXFDFOptions();
    option.SetForce(true);
    doc.MergeXFDF(xfdfString,option);
    //doc.FDFUpdate(FDFDoc.CreateFromXFDF(xfdfString)); //I tried this when I use exportAnnotations() in last step instead
    byte result = doc.Save(pdftron.SDF.SDFDoc.SaveOptions.e_linearized);
    //using the result to save the PDF as I want
}

However, I found that using this method to save the PDF may cause the rotation of free text is not being saved.
So I compared the result of exportAnnotations().
exportAnnotations() right after the annotation is performed:

<?xml version="1.0" encoding="UTF-8" ?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<pdf-info xmlns="http://www.pdftron.com/pdfinfo" version="2" import-version="4" />
<fields />
<annots>
	<freetext page="0" rect="47.800,86.880,594,720.701" flags="print" name="b55defd7-7b81-1498-4ad8-6eec3d7ccc22" title="Demo User1" subject="Free Text" rotation="55.174" date="D:20230508134030+08'00'" width="0" creationdate="D:20230508134016+08'00'" TextColor="#E44234" FontSize="68">
		<trn-custom-data bytes="{&quot;trn-wrapped-text-lines&quot;:&quot;[\&quot;Testing the rotation \&quot;]&quot;,&quot;trn-unrotated-rect&quot;:&quot;21.275,279.551,620.525,528.030&quot;}"/>
		<contents>Testing the rotation</contents>
		<contents-richtext>
			<body><p><span>Testing the rotation</span></p></body>
		</contents-richtext>
		<defaultappearance>0 0 0 rg /Helvetica 68 Tf</defaultappearance>
		<defaultstyle>font: Helvetica 68pt; text-align: left; text-vertical-align: top; color: #E44234</defaultstyle>
	</freetext>
</annots>
<pages><defmtx matrix="1,0,0,-1,0,843.1" /></pages>
</xfdf>

exportAnnotations() of viewing the pdf saved using the above method:

<?xml version="1.0" encoding="UTF-8" ?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<pdf-info xmlns="http://www.pdftron.com/pdfinfo" version="2" import-version="4" />
<fields />
<annots>
	<freetext TextColor="#E44234" width="0" creationdate="D:20230508134016+08'00'" flags="print" date="D:20230508134030+08'00'" name="b55defd7-7b81-1498-4ad8-6eec3d7ccc22" page="0" rect="47.8,86.88,594,720.701" rotation="55.174" subject="Free Text" title="Demo User1">
			<defaultstyle>color:#E44234;font:Helvetica 68pt;text-align:left;text-vertical-align:top;</defaultstyle>
			<trn-custom-data bytes="{&quot;trn-unrotated-rect&quot;:&quot;21.275,279.551,620.525,528.030&quot;}"/>
			<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>Testing the rotation</span></p></body>
			</contents-richtext>
			<defaultappearance>0 0 0 rg /Helvetica 68 Tf</defaultappearance>
			<contents>Testing the rotation</contents>
			<apref y="720.701" x="47.8" gennum="0" objnum="96"/>
	</freetext>
</annots>
<pages><defmtx matrix="1,0,0,-1,0,843.1" /></pages>
</xfdf>

Now what should I do? Thanks.

Hi William,

After calling MergeXFDF, you need to call doc.refreshAnnotAppearances. For more information on why you need this, see the following forum post:

This PDF specification also be default only allows rotations of 90 degrees. If you are doing partial rotations you will need to add the following lines of code after the MergeXFDF

RefreshOptions refreshOptions = new RefreshOptions();
refreshOptions.SetUseNonStandardRotation(true);
doc.refreshAnnotAppearances(refreshOptions);