Programmatically scroll to top of page

Which product are you using?
PDFJs Express 8

PDF.js Express Version
Version 8
Detailed description of issue
When I load a document, I initiate a searchText() after the document is loaded in order to find if the text exists. In my searchListener, the last line is documentViewer.displayFirstPage(); in order to present the first page of the document as shown below.
In most cases, the behavior that I’m expecting, i.e., the first page of the document being displayed starting at the beginning of the document, works. However, I’m finding that it doesn’t always work like that for all documents that I’m loading. In some cases, what is displayed is the page the text was found on and the section containing the text (e.g. bottom of the page).

Expected behaviour
The expected/desired behavior is that for each document, the first page, beginning at the top of the document will be displayed.

Does your issue happen with every document, or just one?
It’s random

Link to document
{Provide a link to the document in question if possible}

Code snippet

 const searchListener = async (searchPattern, options, results) => {
    if (results.length > 0) {
      const y1 = await results.map((result) => {
        return result.quads[0].y1;
      });
      freeText.Y = y1[0] + 5;
    }
       
    documentViewer.displayFirstPage();
   };

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here

Hi Dcheli,

Have you tried moving documentViewer.displayFirstPage(); to the last time in your loadDocument logic? Does that change the behaviour at all?

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.


Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here

Thanks for the suggestion, but that didn’t work. There is something odd going that I noticed. The unexpected behavior that I’m experiencing is only on pdf files that I have saved with the below code. Possibly there is something with this. I don’t want to turn this thread into a confusing thread, so maybe I should look closer into this and if I find an issue start another thread.

const options = {
  filename: filename,
  xfdfString: xfdfString,
  flags: instance.Core.SaveOptions.LINEARIZED,
  downloadType: "pdf",
};

instance.UI.downloadPdf(options);

Hi Dcheli,

Yes if you could pinpoint exactly what is causing the issue and get back to me, that would be helpful in solving the issue.

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.


Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here