Autodesk PDF Extension - Preventing page in query string override

Viewed 89

I'm currently looking to implement pagination within the ForgeViewer PDF Extenstion, in the documentation there's a note that 'page' in the querystring will override any value passed to load model. I wondered if this was configurable or we were able to prevent this.

// URL parameter page will override value passed to loadModel 

viewer.loadModel(‘path/to/file.pdf’, { page: 1 });

This is causing us a few issues as we use 'page' for other purposes and we'll have to rework quite a bit to rename our current page querystring which we're using for paginating tables.

1 Answers

That's correct. If you look inside the PDF extension's code (https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/extensions/PDF/PDF.js) then you'll find that this behaviour is hardcoded unfortunately enter image description here

I can think of two workarounds:
a) Use a URL param other than page - e.g. sheet?

b) Overwrite the current URL so that the page number will become what you need

// Original URL is: http://127.0.0.1:5500/index.html?page=2
// we change it to page=1
// This should change the URL content without a reload
history.pushState('', '', 'index.html?page=1');
viewer.loadModel("AutoCAD_Sample_Part1.pdf", {}, (model) => {

You could also achieve the same like this:

viewer.loadExtension('Autodesk.PDF').then(function(ext) {
  // Original URL is: http://127.0.0.1:5500/index.html?page=2
  // we change it to page=1
  viewer.loadModel("AutoCAD_Sample_Part1.pdf", {}, (model) => {
    ext.hyperlinkTracker.changePage(1) 
Related