Pregunta

Would it be possible to use pdf.js to display a PDF file in Android WebView?

I know the common solution is to use google doc or launch an intent. However, I wish to open it in my app anyway.

It seems that pdf.js provide a pretty good solution to display pdf in browser. I want to know if I can do the same on Android. I want to download the pdf file to a temporary place first, and then display it in WebView.

¿Fue útil?

Solución

Yes you can, if you can render something in your browser, in this case a webkit based browser. you can do it in your webview too but will take much time than your desktop browser.

There is new api for PDF in Kit-Kat, am not sure if it can render a PDF file.

Otros consejos

Yes, you can. here is one thing you may need to pay attention -- protocol choice and a http server

You can use "file://" or "http:" as the url protocol to let webkit to load the viewer.html.

If you use "file:///", you may find the cross domain issue. (error message looks like "XMLHttpRequest cannot load file://mnt/sdcard/somewhere/cache/web/locale/locale.properties. Cross origin requests are only supported for HTTP."), and there will be the similar problem if you put the pdf files in some other places.

The resolution to this issue may be to revise the viewer.html to convert it as a single file.

If you use "http:" as the protocol, you may need a small http server in you Android device.

Good Luck

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top