Where can I find code snippets for WebViewer 5.0 or earlier?

With the release of WebViewer 6.0, code snippets of all the guides have been updated to include only v6.0+ and v5.1+. If you are still using WebViewer 5.0.x, you can use v5.1+ snippets with a few tweaks.

The biggest difference between WebViewer 5.1 and 5.0 is how it is instantiated. The promisified instantiation isn't available in 5.0 so you need to listen to the ready event instead. Also, objects and namespaces such as Annotations, Tools, CoreControls aren't attached to the instance object in 5.0 so you need to grab them from the iframe window.

JavaScript

1// v5.1+
2WebViewer({
3 ...
4}, document.getElementById('viewer'))
5 .then(instance => {
6 const {
7 docViewer,
8 annotManager,
9 Tools,
10 Annotations,
11 CoreControls,
12 PartRetrievers,
13 Actions,
14 PDFNet,
15 } = instance;
16
17 // call instance APIs here
18 });

JavaScript

1// v5.0
2const viewerElement = document.getElementById('viewer');
3const viewer = new PDFTron.WebViewer({
4 ...
5}, viewerElement);
6
7viewer.addEventListener('ready', () => {
8 const instance = viewer.getInstance();
9
10 const docViewer = instance.docViewer;
11 const annotManager = docViewer.getAnnotationManager();
12 const {
13 Tools,
14 Annotations,
15 CoreControls,
16 PartRetrievers,
17 Actions,
18 PDFNet,
19 } = document.querySelector('iframe').contentWindow;
20
21 // call instance APIs here
22});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales