Can we significantly reduce the memory?

Hi Ricky,

Currently we don’t support splitting of the modules when certain features aren’t being used. This is a longer term thing that we’re looking into but don’t yet have a timeline for when it would be available.

For loading multiple instances of WebViewer on the same page the main thing that you can do to save memory is to share the PDF worker objects across all viewer instances. Here are the steps to do this:

  1. Include a script tag pointing to webviewer-core.min.js directly on your app’s HTML page. webviewer-core.min.js is normally only loaded inside the iframe but in this case we also need to load it on your app’s page so that we can create the workers there.
  2. Use code similar to the following when instantiating your WebViewer instances. Basically you need to create a “worker transport promise” which will be passed to each WebViewer instance. This will allow each instance to share the same worker. The worker path may need to be adjusted as it will be relative to your HTML file. In this example I modified the viewing sample included in the WebViewer download package but you may need to adjust the path.
Core.setWorkerPath('../../../lib/core');

Core.getDefaultBackendType().then((backendType) => {
  const workerHandlers = {};
  const licenseKey = 'LICENSE_KEY_HERE';

  const workerTransportPromise = Core.initPDFWorkerTransports(backendType, workerHandlers, licenseKey);

  WebViewer({
    path: '../../../lib',
    licenseKey,
    initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf',
    workerTransportPromise: {
      pdf: workerTransportPromise
    }
  },
  document.getElementById('viewer')).then(instance => {
    samplesSetup(instance);
  });

  WebViewer({
    path: '../../../lib',
    licenseKey,
    initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf',
    workerTransportPromise: {
      pdf: workerTransportPromise
    }
  },
  document.getElementById('viewer2')).then(instance => {
    samplesSetup(instance);
  });
});

Matt Parizeau
Software Developer
PDFTron Systems Inc.