Reuse of existing viewer instance

Product: PDFTron WebViewer

Product Version: 8.3.2

Please give a brief summary of your issue:
How can I reuse an existing WebViewer instance in a modified DOM?

I have written a wrapper for the PDFTron WebViewer which allows to use it in combination with the SAP UI5 framework.
In certain situations the UI5 framework rerenders parts of the HTML and I want to reuse an already existing WebViewer instance.
Instead of creating a new instance

 if (this._webViewerInstance) {
  // reuse this._webViewerInstance ?????
} else {

  void WebViewer(
    {
      path: "../pdftron/lib/public",
      fullAPI: true,
      initialDoc: null
    },
    this.getDomRef() as HTMLElement
  ).then(
    (webViewer: WebViewerInstance) => {
      this._webViewerInstance = webViewer;
    }
  );
}

I want to attach the existing instance stored in this._webViewerInstance to the new DOM. How can I achieve this?

Hi,

Thank you for contacting WebViewer’s support. WebViewer create an iframe and store data inside of it. If UI5 re render (remove from DOM and add back) the element WebViewer is pointing to, there would be issues. You should try adding a component onto the top level of your application and use CSS to show and hide WebViewer (use “visibility: hidden” or “height: 0px”, avoid using “display: none” because some browsers will try to garbage collect data in the iframe). You can set the position to absolute and position WebViewer to where it’s needed.

Please let me know if the above helps or if you want me to clarify something.

Best Regards,

Andrew Yip
Software Developer
PDFTron Systems, Inc.
www.pdftron.com