Search code examples
pdftron

How do I get the annotations from the active Tab


Currently, when I get the annotations from the annotationManager, they are coming back empty for the current document, do we need to manage annotationMangers for each tab?

const allAnnotList = annotationManager.getAnnotationsList();

Anyone with any experience using PDFTron tab view for multiple documents.

  1. Does each tab have a documentViewer or is this global and updated when the tab is changed.
  2. Does the annotationManager hold all annotations or just for the current documentViewer

I have narrowed down the issue to the below function call:

currentAnnotationManger.exportAnnotations

currentAnnotationManger.exportAnnotations Confirmed we have a list of annotations below:

[
  {
    "BU": true,
    "Subject": "client-Client 1-0",
    "WF": 1,
    "Gz": 261,
    "Hz": 197,
    "Ru": 96,
    "Qu": 32,
    "Rotation": 0,
    "le": {
      "x": 309,
      "y": 213
    },
    "AO": 50.59644256269407,
    "Dz": false,
    "DO": false,
    "EO": false,
    "ni": {
      "trn-annot-maintain-aspect-ratio": "true",
      "trn-unrotated-rect": "261,626,357,658"
    },
    "Bz": true,
    "yO": false,
    "UF": false,
    "Pu": false,
    "zO": false,
    "TF": false,
    "NoZoom": false,
    "NoRotate": false,
    "FO": true,
    "Nm": null,
    "TO": "Agent Id : 62b11e644180cb09e786ec7d",
    "iG": "2022-10-28T03:47:54.535Z",
    "hA": "d9b4efdc-af38-d203-5a41-0139451aecd4",
    "xG": true,
    "fp": false,
    "KP": false,
    "iQ": {},
    "Wk": [],
    "gh": null,
    "uE": null,
    "ZK": null,
    "qr": [],
    "Uo": {},
    "To": {},
    "CO": null,
    "GO": null,
    "yj": null,
    "zj": null,
    "aQ": 1,
    "Y3": null,
    "eP": "2022-10-28T03:47:50.793Z",
    "CA": null,
    "_xsi:type": "Stamp",
    "oi": "Draft",
    "Cy": "Draft",
    "Ya": null,
    "Vw": 1,
    "canvas": {},
    "K7": "bold italic 30px sans-serif",
    "ToolName": "AnnotationCreateRubberStamp",
    "image": {}
  },
  {
    "BU": true,
    "Subject": "agent",
    "WF": 1,
    "Gz": 200,
    "Hz": 300,
    "Ru": 96,
    "Qu": 32,
    "Rotation": 0,
    "le": {
      "x": 248,
      "y": 316
    },
    "AO": 50.59644256269407,
    "Dz": false,
    "DO": false,
    "EO": false,
    "ni": {
      "trn-annot-maintain-aspect-ratio": "true",
      "trn-unrotated-rect": "200,523,296,555"
    },
    "Bz": true,
    "yO": false,
    "UF": false,
    "Pu": false,
    "zO": false,
    "TF": false,
    "NoZoom": false,
    "NoRotate": false,
    "FO": true,
    "Nm": null,
    "TO": "Agent Id : 62b11e644180cb09e786ec7d",
    "iG": "2022-10-28T03:47:54.535Z",
    "hA": "58dc723e-da36-5f4e-16d5-fe6ae32f5252",
    "xG": true,
    "fp": false,
    "KP": false,
    "iQ": {},
    "Wk": [],
    "gh": null,
    "uE": null,
    "ZK": null,
    "qr": [],
    "Uo": {},
    "To": {},
    "CO": null,
    "GO": null,
    "yj": null,
    "zj": null,
    "aQ": 1,
    "Y3": null,
    "eP": "2022-10-28T03:47:53.499Z",
    "CA": null,
    "_xsi:type": "Stamp",
    "oi": "Draft",
    "Cy": "Draft",
    "Ya": null,
    "Vw": 1,
    "canvas": {},
    "K7": "bold italic 30px sans-serif",
    "ToolName": "AnnotationCreateRubberStamp",
    "image": {}
  }
]


Solution

  • For your questions

    Does each tab have a documentViewer or is this global and updated when the tab is changed.

    There is only one active "documentViewer" that get updated when tab are changed. Currently tab data is stored in the UI.TabManager. The UI part of the codebase is open sourced so you can see what the TabManager does in the link below

    https://github.com/PDFTron/webviewer-ui/blob/8.9/src/helpers/TabManager.js

    Does the annotationManager hold all annotations or just for the current documentViewer

    There is only one annotationManager that hold the current annotations for the active tab. When you change tab, the current data (annotations, scroll position, etc) are stored in the TabManager and get restored when you switch back to that tab.

    Currently there isn't an API to get annotations for non active tab, you'll need to get it before the tab change, during the beforeTabChanged event (it sounds like that what you are doing now)

    Best Regards