简体   繁体   English

如何在Android中打开PDF?

[英]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. 您好我正在尝试在Android中打开pdf文件。我在Android中是一个非常新的人。我在项目中包含了PDF文件..现在如何在第一个视图中打开该pdf文件。该PDF文件有20页。我可以在webview中打开它,也可以使用其他选项。请有人帮助我?这是很小的帮助。 Thans for your time. 谢谢您的光临。

There is no pre-built way in Android to view PDFs. Android中没有预构建的方式来查看PDF。

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) 有一些免费的库,但大多数是GPL-因此不适合在封闭源应用中使用)
    If you don't have to keep your app closed source, I'd recommend eg this library: https://github.com/JoanZapata/android-pdfview 如果您不必关闭您的应用程序的源代码,我建议例如该库: https : //github.com/JoanZapata/android-pdfview

  • Use Google Docs in a WebView like in this question . 这个问题一样在WebView使用Google文档。

  • Handle the pdf to an external app for displaying. 将pdf处理到外部应用程序以进行显示。 Just create an intent and set the data to your pdf path. 只需创建一个意图并将数据设置为您的pdf路径即可。

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. 除了FD_回答中的“仅”三种可能性外,第四种实际上略有不同,但是它要求您创建自己的Web应用程序。 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. 想法是将pdf发送到网络服务,该服务会读取pdf,将其转换为图像,然后将图像发送回android设备进行显示。

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. 当然,您将需要一些东西来在Web服务器上进行转换,但是与在Android本身上进行加载相比,您将有更多选择,因为服务器可以是任何东西。

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. 我在Web应用程序(HTML5)中使用了这种方法,而我的服务器是Windows&IIS,带有一个称为Lead tools的SDK来加载PDF。 I think they now have an Android sdk too but I haven't tried it. 我认为他们现在也有Android SDK,但我还没有尝试过。

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

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