简体   繁体   English

如何在移动浏览器的 html(react) 中嵌入 firebase 存储中的 pdf 文件

[英]How to embed a pdf file from firebase storage in html(react) in mobile browsers

I have a pdf file in firebase storage with a url like: https://firebasestorage.googleapis.com/v0/b/xxxxxx.appspot.com/o/projectPdfs%2FSuperImportant%20Project.pdf?alt=media&token=0b351324-1ae5-4997-8e7c-f17039a1d3b2 I have a pdf file in firebase storage with a url like: https://firebasestorage.googleapis.com/v0/b/xxxxxx.appspot.com/o/projectPdfs%2FSuperImportant%20Project.pdf?alt=media&token=0b351324-1ae5 -4997-8e7c-f17039a1d3b2

I want to somehow display this in my react app.我想以某种方式在我的反应应用程序中显示它。 I tried using using html object, embed and iframe.我尝试使用 html object、嵌入和 iframe。 All these three methods does not work in mobile browsers.所有这三种方法都不适用于移动浏览器。 It just shows an 'open' button and when clicked automatically downloads the pdf into the device.它只显示一个“打开”按钮,单击时会自动将 pdf 下载到设备中。

I also tried appending the pdf Link to a google PDF viewer url.我还尝试将 pdf 链接附加到谷歌 PDF 查看器 url。

Like喜欢

<iframe src=`https://drive.google.com/viewerng/viewer?url=${my_firebase_pdf_url}` width="400px" height="300px"  />

But this didn't work as well.但这也没有奏效。 Now an 'open' button shows which when clicked opens a new tab and says 'no preview available' with an option to download the file.现在,“打开”按钮会显示单击该按钮会打开一个新选项卡并显示“没有可用的预览”以及下载文件的选项。 I tried with the urls of other pdf files not stored in firebase and now it seems to work fine.我尝试使用未存储在 firebase 中的其他 pdf 文件的 url,现在它似乎工作正常。

I don't want to download the pdf to the device.我不想将 pdf 下载到设备上。 I just need to embed it somehow like how it works perfectly in the desktop versions.我只需要以某种方式嵌入它,就像它在桌面版本中完美运行一样。

I tried libraries like react-pdf, pdf-viewer-react-js etc, but all of them couldn't help me.我尝试了 react-pdf、pdf-viewer-react-js 等库,但它们都帮不了我。 I've been struggling for 5 days now.我已经挣扎了5天了。 Is this the problem of firebase storage urls and will using someother backend (like node and mongoDB) fix the problem?这是 firebase 存储 url 的问题吗?是否会使用其他后端(如 node 和 mongoDB)来解决问题?

Seems like your browser cannot render pdfs natively.似乎您的浏览器无法原生呈现 pdf。 Also the url you have provided seems to be wrong you might want to correct that.此外,您提供的 url 似乎是错误的,您可能需要更正它。 After correcting the url use the url below to open the file in mobile browser.更正 url 后,使用下面的 url 在移动浏览器中打开文件。

"http://docs.google.com/gview?embedded=true&url=yourfileurl" “http://docs.google.com/gview?embedded=true&url=yourfileurl”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM