Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
How to load multiple documents in WebView from URL (PDFTron)

I am trying to use PDFTron to load several documents and then open them dynamically onClick event. The trouble is I can't access the instance object from outside the return of the WebViewer promise - I need to create dynamic buttons that load a document depending on the button that I click. They are not going to be hardcoded so I can't load in documents from fixed URL's for each button.

Here is the example code from PDFTron. Mine is nearly identical - the only difference is I need the loadDocumentButtons to be dynamic. I don't know a way to do this due to scoping issues; the instance object is trapped within the return of the promise and I don't know how to access it from outside the promise return. Can anyone help with this?

WebViewer({
  ...
}, viewerElement)
  .then(instance => {
    loadDocumentButton.on('click', () => {
      instance.loadDocument('mysite.com/myDocument.pdf', { documentId: 'id2' });
    });

    loadAnotherDocumentButton.on('click', () => {
      instance.loadDocument('mysite.com/myOtherDocument.pdf', { documentId: 'id2' });
    });
  });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are a couple of different approaches you could take. The first is to use a config file, which is basically a javascript file that gets executed in the context of the iframe in which WebViewer is run. Example:

WebViewer({
  initialDoc: "mydoc.pdf",
  config: "path/to/my/config/file.js" // relative to your HTML file
}, viewerElement);

Inside the config file you will have access to the Document, DocumentViewer and AnnotationManager objects (among others). Config Files

You can also call the getInstance API, which returns an existing instance of WebViewer.

import { getInstance } from '@pdftron/webviewer'

// After WebViewer has already been constructed
const instance = getInstance();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!