swissspidy / media-experiments

WordPress media experiments
GNU General Public License v2.0
73 stars 1 forks source link

Use PDF.js for inline embeds #277

Open swissspidy opened 8 months ago

swissspidy commented 8 months ago

The file block has this support for inline embeds/previews for PDFs and other file types. Doesn't really seem to work in the editor, and on the frontend support is limited.

It could be interesting to expand support by using PDF.js for viewing PDF files.

Would need to see how lightweight it is etc. But the viewer could possibly be lazy loaded and first display the poster image.

Would be interesting to query HTTP Archive for wp-block-file__embed usage. Maybe add to https://github.com/felixarntz/custom-metrics/blob/main/dist/cms.js? Though seems like these embeds are rather lightweight as it just requires loading the PDF file and nothing more. So adding PDF.js on top of that would be heavier.

Notes from the doc:

The viewer is built on the display layer and is the UI for the PDF viewer in Firefox and the other browser extensions within the project. It can be a good starting point for building your own viewer. However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.

swissspidy commented 2 weeks ago

Doesn't really seem to work in the editor, and on the frontend support is limited.

It does work, but not with cross-origin isolation, as <object> doesn't support crossorigin.

So at least in the editor using PDF.js seems like the only way to address this.