简体   繁体   中英

How to open a pdf in Android?

Hello I am trying to open a pdf file in Android .I am very new in Android .I have include PDF file in the project ..Now How can I open that pdf file on my first view.The PDF file contacts 20 pages.Should I open it in webview or there are some other options .Please someone can help me in this ??Its a very small help. Thans for your time.

There is no pre-built way in Android to view PDFs.

Here are your possibilities:

  • Use a third-party library
    There are some free libraries, but most are GPL - so not for use in closed-source apps)
    If you don't have to keep your app closed source, I'd recommend eg this library: https://github.com/JoanZapata/android-pdfview

  • Use Google Docs in a WebView like in this question .

  • Handle the pdf to an external app for displaying. Just create an intent and set the data to your pdf path.

In addition to the "only" three possibilities in FD_'s answer, there's actually a slightly different fourth, but it requires that you create your own web application. The idea is to send the pdf to a web service that reads it, converts it to images and sends the images back to the android device for display.

Of course you will need something to do the conversion on the web server, but you will have many more choices than doing the loading on Android itself, because the server can be anything.

I used this approach in a web application (HTML5) and my server was Windows & IIS with an SDK named Lead tools to load the PDF. I think they now have an Android sdk too but I haven't tried it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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