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

Match accessibility features offered by pdfjs viewer #1494

Closed
2 tasks done
MattL75 opened this issue May 8, 2023 · 3 comments
Closed
2 tasks done

Match accessibility features offered by pdfjs viewer #1494

MattL75 opened this issue May 8, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@MattL75
Copy link
Contributor

MattL75 commented May 8, 2023

Before you start - checklist

  • I understand that React-PDF does not aim to be a fully-fledged PDF viewer and is only a tool to make one
  • I have checked if this feature request is not already reported

Description

This feature was previously sortof reported here: #831 but was closed without a proper conclusion.

The idea is to provide an accessibility layer that matches what is offered in the pdfjs viewer. Here's an example.
Screen Shot 2023-05-08 at 3 49 02 PM

In a nutshell, it makes use of the pdf tagging feature and displays informational semantic data that screenreaders can tap into.

<canvas>
  <span role="heading" aria-level="1" aria_owns="heading_id"></span>
  <span aria_owns="some_paragraph"></span>
</canvas>

In the text layer:
<span id="heading_id">Some Heading</span>
<span id="some_paragaph">Hello world!</span>

Proposed solution

The solution isn't actually super difficult to implement. I have a working PoC locally with our fork (react-pdf v6) and it doesn't have a huge amount of changes. I will be implementing this properly in a sprint soon and I'd like to contribute it upstream to react-pdf.

The key is the following function with property:
getTextContent({includeMarkedContent: true})

We can then use this automatically by passing it to renderTextLayer function from pdfjs.

In my tests on an older pdfjs version, it was required to use the STREAM of the text content in the renderTextLayer function to obtain a properly-formatted DOM.

We can then have a component which recursively renders the struct tree associated with the marked content.

Alternatives

No response

Additional information

As mentioned above, I have most of this figured out locally in a rough PoC.

@wojtekmaj Is this something you feel is within the scope of react-pdf? Or rather something I should keep within my fork. No problems either way :)

@MattL75 MattL75 added the enhancement New feature or request label May 8, 2023
@wojtekmaj
Copy link
Owner

wojtekmaj commented May 8, 2023

HELL TO THE YEAH, accessibility isn't a feature, it's a foundation. If there's any feature implemented in React-PDF that provides subpar experience for folks using assistive technologies, I'd consider it a bug.

Please go ahead!

Show me what you got

@wojtekmaj wojtekmaj added the fresh label May 8, 2023
@rihards-simanovics
Copy link

rihards-simanovics commented May 13, 2023

Hey Guys, actually working to implement this package on a semi governmental website, I really like that you provide a semi accessible text layer (presumably the idea was to make text selectable for easy of copy and paste). I can see this also be useful for the narrator, however making all of the text to be span isn't helpful. Is there any react hooks or any other way to make this customisable, say content hierarchy h1, h2, h3, ..., p, b ,etc?

Edit:
@MattL75 just read the rest of the issue, if you can share here when you make a pull request this would be awesome, I can test it on my side as well! Oh and thanks for great work!

Edit 2:
guess you already did #1498

@MattL75
Copy link
Contributor Author

MattL75 commented May 13, 2023

@rihards-simanovics Yes as you saw I have made the PR. If you can test it out that would be great. Keep in mind the documents still need to be tagged (using acrobat) for the semantic tags to show up. Without a tagged document, no way to show accessible :)

@wojtekmaj wojtekmaj removed the fresh label Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants