WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.47k stars 4.18k forks source link

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

Open sejas opened 1 year ago

sejas commented 1 year ago

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

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

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 commented 1 year ago

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 commented 1 year ago

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
Thelmachido commented 1 year ago

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

sejas commented 1 year ago

@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 commented 2 weeks ago

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.