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

File Block: PDF preview not working on mobile devices iOS and Android #46382

Open
sejas opened this issue Dec 7, 2022 · 5 comments
Open

File Block: PDF preview not working on mobile devices iOS and Android #46382

sejas opened this issue Dec 7, 2022 · 5 comments
Labels
[Block] File Affects the File Block [Type] Bug An existing feature does not function as intended

Comments

@sejas
Copy link
Contributor

sejas commented Dec 7, 2022

Description

Embedding a PDF file using the core/file block is not rendering an interactive preview on mobile devices.

Expected behavior

The PDF should be displayed as an embed with the ability to scroll through multi-page files, as it does on desktop. Alternatively, the whole preview could be hidden for mobile, displaying only the buttons to preview and download.

Actual behavior
The PDF only displays the first page using a distorted image, without the option to scroll through the rest of the pages. Additionally, the content is displayed against the site's background, ignoring the PDF's original background, making it hard to identify it as a "preview".

Possible solutions

  • iframe seems to render the pdf preview, but the UX is not the best.
  • hide the preview if the device it's not supported, or the browser agent is a mobile device.
  • Add an extra option to the file block to hide the preview for mobile devices. This is the best solution from my point of view.

Other notes

Step-by-step reproduction instructions

  1. Embed a PDF file on a post or page using the core/file block.
  2. Open the page/post on an iOS or Android device.
  3. Observe the PDF preview is not working, resulting in a bad UX.

Screenshots, screen recording, code snippet

iOS Android
ios android

iOS with pink background

Environment info

  • WP 6.1.1, Gutenberg 14.6.1
  • Safari, Chrome
  • iPhone 13 iOS 16.1, Android Galaxy S22

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@danielbachhuber
Copy link
Member

hide the preview if the device it's not supported, or the browser agent is a mobile device.

We could potentially hide the preview and show a direct link to the file instead?

@sejas
Copy link
Contributor Author

sejas commented Dec 8, 2022

We could potentially hide the preview and show a direct link to the file instead?

The file component already has buttons to download the file. Hiding the preview would be enough.
Screenshot 2022-12-08 at 12 24 47

@kathrynwp kathrynwp added [Type] Bug An existing feature does not function as intended [Block] File Affects the File Block labels Dec 12, 2022
@Thelmachido
Copy link

I am able to preview PDF files on my IOS, I am not sure if this is still relevant can you please check @sejas and @danielbachhuber

@Thelmachido Thelmachido added the [Status] Needs More Info Follow-up required in order to be actionable. label May 17, 2023
@sejas
Copy link
Contributor Author

sejas commented May 17, 2023

@Thelmachido , only the first page of the PDF is visible, appearing like a stretched "screenshot". It doesn't offer a multipage preview, unlike the desktop version which allows users to view the entire embedded PDF. Additionally, there are issues with the background, making it challenging to discern the PDF's boundaries.
Both the filename/sample and Download buttons have identical functionality. They both link to the PDF, which subsequently opens in the same tab.

I could reproduce this behavior today.

I understand that this is the natural iOS behavior, but we can improve it by adding borders and a white background. And probably removing one button or allowing the Download button to actually download the PDF.

@michael-sumner
Copy link

The browserSupportsPdfs util function must be refactored to use the HTML Standard navigator.pdfViewerEnabled instead.

Note

This method replaces a number of legacy methods of inferring support for inline viewing of PDF files.

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/pdfViewerEnabled

That way, we can avoid relying on User Agents, and allow modern browsers to dictate the display of the PDF viewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] File Affects the File Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

6 participants