Skip to content
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

Add new "pageopen"/"pageclose" events for usage with JavaScript actions #12747

Merged
merged 2 commits into from
Dec 18, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

Please refer to the individual commit messages for additional information.

https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_api_reference.pdf#G5.1963437

@timvandermeij I really hoped to be able to use e.g. the existing "pagechanging" events, but based on the requirements outlined in the specification I just don't see a better way than adding new events here; please let me know if you have a better idea!

Having looked at the Acrobat JavaScript specification, see https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_api_reference.pdf#G5.1963437, I suppose that introducing these two new events is probably the easiest solution overall.

However there's a number of things that, as far as I'm concerned, will help the overall implementation:
 - Only dispatch these new events when `enableScripting = true` is set.
 - Handle them *separately* from the existing "pagechanging" event dispatching, to avoid too much clutter.
 - Don't dispatch either of the events if the page didn't actually change.
 - When waiting for pages to render, don't dispatch "pageopen" if the page is no longer active when rendering finishes.
 - Ensure that we only use *one* "pagerendered" event listener.
 - Ensure that "pageopen" is actually dispatched when the document loads.

I suppose that we *could* avoid adding the "pageclose" event, and use the existing "pagechanging" event instead, however having a separate event might allow more flexibility in the future. (E.g. I don't know if we'll possibly want to dispatch "pageclose" on document close, as mentioned briefly in the specification.)
…removes an existing document

This new event essentially mirrors the existing "pagesinit" event, and will allow e.g. a custom implementation of the viewer to be notified before the current PDF document is removed from the viewer.

By using this new event, we're thus able to dispatch a "pageclose" event for JavaScript actions when closing the existing document.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/52c1fc1f4b5820e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/52c1fc1f4b5820e/output.txt

Total script time: 4.19 mins

Published

Copy link
Contributor

@calixteman calixteman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WFM, thanks a lot.
I'll add an integration test in a followup.

@timvandermeij timvandermeij merged commit 6efd350 into mozilla:master Dec 18, 2020
@timvandermeij
Copy link
Contributor

Looks like a good solution to me too!

@Snuffleupagus Snuffleupagus deleted the pageopen-pageclose branch December 18, 2020 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants