PDF.js Express Version: 8.x.x
We exported annotations as XFDFs, but could not import XFDFs. We tried to pass xfdfString value to annotationManager.importAnnotCommand(xfdfString) function. The result is empty array. We would like to know how we could import XFDFs.
Here is what we referenced.
The below code is about exporting XFDFs.
<?xml version="1.0" encoding="UTF-8" ?>
Here is importing code:
useEffect(() => {
WebViewer(
{
path: '../../../webviewer/lib',
initialDoc: 'https://s3.ap-northeast-2.amazonaws.com/crossxxx/xxx/drive/wGmxxxx.pdf',
},
viewer.current
).then((instance) => {
const { annotationManager, documentViewer } = instance.Core
// load the annotation data as a transaction command
fetch('https://apixxx.crossxxxx.cxxxx/pdf-web/715', {
method: 'GET',
}).then((response) => {
if (response.status === 200) {
response.text().then(async (xfdfString) => {
console.log('xfdfString', xfdfString)
// <xfdf>
// <add>
// <text subject="Comment" page="0" color="#FFE6A2" ... />
// </add>
// <modify />
// <delete />
// </xfdf>
const annotations = await annotationManager.importAnnotCommand(xfdfString) // empty array is returned
console.log('annotations', annotations)
annotations.forEach((annotation) => {
annotationManager.redrawAnnotation(annotation)
})
})
}
})
})
},[])
Please let us know what to do.
Thanks in advance,
Heejung