开发者

Issue displaying pdf on android using <object> html tag

开发者 https://www.devze.com 2023-04-07 09:02 出处:网络
I am trying to display a PDF to a web page using the html [object] tag.This works fine on all the web browsers on PC\'s as well as iPhone/iPad.But when I load the same page on an Android it asks me if

I am trying to display a PDF to a web page using the html [object] tag. This works fine on all the web browsers on PC's as well as iPhone/iPad. But when I load the same page on an Android it asks me if I want to download the file which is the backup when the PDF isn't displayed. Does anyone know why this wouldn't work or another html control I could use rather than forcefully calling the local PDF program on the phone.

Below is how my html is rendered.

<object data="../myFile.pdf" type="application/pdf" width="100%" height="100%">
    <p>Missing PDF plugin for this br开发者_运维问答owser.<a href="../myFile.pdf">Click here to download the PDF file.</a></p>
</object>

I have also seen examples on stackoverflow suggesting the below code but I am unsure of how to leverage it on my site and was hoping there was a possible html fix.

WebView webview = new WebView(this); 
setContentView(webview); 
webview.getSettings().setJavaScriptEnabled(true); 
webview.loadUrl("URL/Demo_PDF.pdf");

The phone I am using is a Thunderbolt. Thanks for the help.


Does anyone know why this wouldn't work

Because that is not supported on Android.

or another html control I could use rather than forcefully calling the local PDF program on the phone.

There may not even be a "local PDF program on the phone". Many phones ship with one, many users install one, but there is no guarantee.

But, beyond that, there is no way to display PDFs natively inline in the stock Android browser. A third party one might support it (e.g., Firefox). Converting the PDF to a Flash animation might work with the stock Android browser, though that will only work on Android 2.2 and higher.

but I am unsure of how to leverage it on my site

You wouldn't. That is Java code, for an Android application.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号