-
-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for broken search functionality when showPage=false #393
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The PDFFindController of PDF.js wasn't able to search on a PDFPageView, replacing it with the PDFSinglePageViewer solved the issue. This change unfortunately introduced some major changes in the inner functioning of the pdf-viewer.
Errors included trailing whitespaces, unneccessary type declarations and member ordering.
The setupViewer methods didn't need to be public. Cleanup included removing trailing whitespaces.
The reason that we have to specify a new eventbus is the default behavior of pdfjs viewers. If you don't specify an eventbus at creation, a viewer will get a singleton instance of a global eventbus. Meaning that two viewer instances (in our case PDFSinglePageViewer and PDFViewer) share one eventbus. Since PDFSinglePageViewer reacts to 'pagesinit' events by calling '_ensurePageViewVisible()' (see pdfjs source code) the single viewer throws an error. Using an unmodified new EventBus instance however resulted in important events not being thrown at document level (f.e. 'pagerendered'). By copying the implementation of a global EventBus from 'pdf.js/web/dom_events.js', the normal behavior is restored with separat EventBus instances.
The EventBus creation shouldn't be a responsibility of the pdf-viewer, so it was moved to a utility file. When pdfjs exports their methods contained in 'pdf.js/web/dom_events.js' these utility classes can be removed in favor of them.
When trying to package the project it threw the following error: "packagr Exported variable 'createEventBus' has or is using private name '_createEventBus'." This should be fixed now.
Forgot to replace all instances of pdfMultiPageViewer (former pdfViewer) with getCurrentViewer().
Previously using the PDFPageView and changing the page there resulted in a just the pdf page get changed out with the new one. By using the PDFSInglePageViewer a page change results in focusing the new pdf page requesting focus "snapping" into view. If the page change is triggered by an input element whose position is fixed, it may get out of the users viewport, which isn't very pretty. The input still receives inputs (like pressing up/down keys on keyboard) but the user can't see the input element itself (an example of this behavior can be found in by executing "ng serve".
Great job, I'll review it as soon as I can! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prologue
This is my first fork/PR of an open source porject, so please point out errors if found, thanks!
Issues getting fixed by this PR
General Overview
While working on an integration in a current web-frontend project I noticed, that the search functionality was not working when displaying only a single page (with showAll = false).
I saw that the viewer used a PDFPageView to display a single page and a PDFViewer for all pages. By this, the content of the PDF could only be searched, when the PDFViewer was displaying all pages.
This fix uses the PDFSinglePageViewer (https://github.com/mozilla/pdf.js/blob/master/web/pdf_single_page_viewer.js) instead of a PDFPageView, which causes a lot of changes internally, thus the many changes in this PR.
Most important changes
Please note the changes to the following methods: