Hello dcheli,
Thank you for the additional details. I think the issue might have something to do with how you are setting the elementName
property in this line:
approvedAnnot.elementName = 'ilr-approve'; // this property cannot be set during the initialization above
I was able to save the annotation by changing this line to use setCustomData()
to save the ‘elementName’ in the XFDF and later use getCustomData
to retrieve it and set the element name as content using the code below which is similar to yours:
Webviewer({
initialDoc: './blank.pdf',
path: '/lib',
}, document.getElementById('viewer')).then(instance => {
const { docViewer, annotManager, Annotations } = instance;
const approvedAnnot = new Annotations.FreeTextAnnotation(undefined, {
Id: 'ilr-approve',
PageNumber: 1,
Y: 720,
X: 150,
Width: 300,
Height: 10,
FillColor: new Annotations.Color(255, 255, 255),
TextColor: new Annotations.Color(0, 0, 0), // black, default is red
FontSize: '6pt',
ReadOnly: true,
StrokeThickness: 0, // border thickness
Hidden: true,
NoResize: true,
NoRotate: true,
NoMove: true,
Printable: true,
});
approvedAnnot.setCustomData('elementName', 'ilr-approve');
annotManager.addAnnotation(approvedAnnot);
const annotationList = annotManager.getAnnotationsList();
if (annotationList) {
annotationList.forEach(async (annotation) => {
selectedAnnotation = annotation;
selectedAnnotation.setContents(annotation.getCustomData('elementName'));
selectedAnnotation.Author = annotation.author;
selectedAnnotation.DateModified = new Date();
selectedAnnotation.Hidden = false;
// now you need the annotationManager
if (!annotManager) alert('no annotManager');
annotManager.redrawAnnotation(selectedAnnotation);
});
};
docViewer.addEventListener('annotationsLoaded', async () => {
const xfdfString = await annotManager.exportAnnotations();
const options = {
filename: 'annotSaveTest',
xfdfString: xfdfString,
flags: instance.Core.SaveOptions.LINEARIZED,
downloadType: 'pdf',
useDisplayAuthor: true,
};
await instance.UI.downloadPdf(options);
});
We have a guide available on saving and loading custom properties (like elementName
in this case) here: Apryse Documentation | Documentation. Would you be able to try this and see if it works?
Best Regards,
Carlo Mendoza
Web Developer
Apryse