# Instance functionality not working

**URL:** <https://pdfjs.community/t/instance-functionality-not-working/2511>\
**Category:** Technical Support\
**Created:** [April 7, 2023, 12:38pm UTC](https://pdfjs.community/t/instance-functionality-not-working/2511 "2023-04-07T12:38:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tejshree.bang](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@tejshree.bang](https://pdfjs.community/u/tejshree.bang)\
**Post date:** [April 7, 2023, 12:38pm UTC](https://pdfjs.community/t/instance-functionality-not-working/2511/1 "2023-04-07T12:38:23Z")

</div>

Hii,  
I have downloaded react project which you have given, It is runnning for viewing but if I am trying to import and export markup then giving some undefined error.  
In instance, there is no core object and if i am calling documentViewer.addEventListener then it is also not working.  
Also can you please guide me for how to save & extract annotations.

WebViewer(  
{  
path: ‘/webviewer/lib’,  
initialDoc: ‘/files/pdftron\_about.pdf’,  
},  
viewer.current,  
).then((instance) =\> {  
const { docViewer, Annotations } = instance;  
const {DocumentViewer} = instance.CoreControls;  
instance.setTheme(‘dark’)  
console.log("instance : ",instance,instance.Core,instance.annotManager.exportAnnotations());  
const annotManager = docViewer.getAnnotationManager();  
DocumentViewer.addEventListener(‘documentLoaded’, async () =\> {  
const fileData = await DocumentViewer.getDocument().getFileData({});  
const blob = new Blob([fileData], {type: ‘application/pdf’})

```
    const data = new FormData();
    data.append('file', blob);
    // data.append('license', my_license_key);

    // Process the file
    const response = await fetch('https://api.pdfjs.express/xfdf/extract', {
      method: 'post',
      body: data
    }).then(resp => resp.json());

    const { xfdf } = response;

    const importedAnnotations = await annotManager.importAnnotations(xfdf);
  })
  // docViewer.on('documentLoaded', async () => {
  // // Save to your database
  // // await saveToDatabase(xfdfString)
  // const rectangleAnnot = new Annotations.RectangleAnnotation();
  // rectangleAnnot.PageNumber = 1;
  // // values are in page coordinates with (0, 0) in the top left
  // rectangleAnnot.X = 100;
  // rectangleAnnot.Y = 150;
  // rectangleAnnot.Width = 200;
  // rectangleAnnot.Height = 50;
  // rectangleAnnot.Author = annotManager.getCurrentUser();

  // annotManager.addAnnotation(rectangleAnnot);
  // // need to draw the annotation otherwise it won't show up until the page is refreshed
  // annotManager.redrawAnnotation(rectangleAnnot);
  // });
});

```

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/3/33259911e019f2f6f856dbb7bf472000848af07a.png)

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [April 10, 2023, 4:21pm UTC](https://pdfjs.community/t/instance-functionality-not-working/2511/2 "2023-04-10T16:21:02Z")

</div>

Hello tejshree.bang

It looks like youre using an older version, please update to the latest version!

You can access documentViewer like so:

```javascript
instance.Core.documentViewer

```

Accessing the DocumentViewer (with a capital D) is the class, not the instance of the class.

Saving and extracting Annotations guide: [Merge & Extract Annotation on PDF.js Express | Documentation](https://pdfjs.express/documentation/annotation/merge-and-extract)

Best regards,  
Tyler Gordon
