WebViewer Version: 8.1.0
I encountered issues when trying to use the getTemplateKeys() as it always return 0 in length.
This is the content of my test.docx file, with the Template Keys defined:
Name of Patient: {{name}}
NRIC: {{NRIC}}
Gender: {{gender}}
Below is the code I used (Modified based on the react sample code)
import React, { useRef, useEffect } from 'react';
import WebViewer from '@pdftron/webviewer';
import './App.css';
const App = () => {
const viewer = useRef(null);
// if using a class, equivalent of componentDidMount
useEffect(() => {
WebViewer(
{
path: '/webviewer/lib',
initialDoc: '/files/test.docx',
},
viewer.current,
).then((instance) => {
const docViewer = instance.Core.documentViewer;
const annotManager = instance.Core.annotationManager;
// call methods from instance, docViewer and annotManager as needed
// you can also access major namespaces from the instance as follows:
// const Tools = instance.Core.Tools;
// const Annotations = instance.Core.Annotations;
docViewer.addEventListener('documentLoaded', () => {
// call methods relating to the loaded document
const doc = docViewer.getDocument();
const keys = doc.getTemplateKeys();
console.log(keys)
// it is possible to extract document template keys in WebViewer
});
});
}, []);
return (
<div className="App">
<div className="header">React sample</div>
<div className="webviewer" ref={viewer}></div>
</div>
);
};
export default App;