Adobe PDF Embed apis.gotoLocation() forces pdf to refresh

342 Views Asked by At

Adobe PDF Embed seems to always reload the pdf instead of just navigating to the correct page (as changing the page number within the iframe does). Is there a way around this?

Code being used: previewFilePromise.then(adobeViewer => {

    adobeViewer.getAPIs().then(apis => {
            apis.gotoLocation(n)
                    .then(() => console.log("Success"))
                    .catch(error => console.log(error));
     });

});

1

There are 1 best solutions below

1
On BEST ANSWER

I haven't seen that behavior but I'm approaching the problem a bit differently. I get the APIs only once and then reuse the object as shown below. A link to a functioning example is after the code snippet.

 var viewerAPI = null;
 function showPDF(urlToPDF) {
      var adobeDCView = new AdobeDC.View({
           clientId: clientId,
           divId: "embeddedView"
      });
      previewFilePromise = adobeDCView.previewFile(
           {
                content: { promise: fetchPDF(urlToPDF) },
                metaData: { fileName: urlToPDF.split("/").slice(-1)[0] }
           },
           viewerOptions
      );
      previewFilePromise.then((adobeViewer) => {
           adobeViewer.getAPIs().then((apis) => {
                viewerAPI = apis;
           });
      });
 }

 function goToPage(pageNum) {
      viewerAPI.gotoLocation(parseInt(pageNum));
 }

Full Codepen