简体   繁体   English

在Android中阅读PDF文档

[英]Reading a PDF Document in Android

this is my first question or rather Questions. 这是我的第一个问题,或者说是问题。 I am in my last semester this college and Reading PDF is one of the components that im developing for my thesis. 我在上一学期这所大学和阅读PDF是我正在为我的论文开发的组件之一。

I have been reading questions about reading a pdf document but there are no solid answer. 我一直在阅读有关阅读pdf文档的问题,但没有可靠的答案。 I want to know what are the ways to read a PDF document? 我想知道阅读PDF文档的方法是什么? what i have read that there are API's available that can read PDF Document like PDFBox, muPDF , and iText . 我所读到的有API可用,可以阅读PDF文档,如PDFBox, muPDFiText I have not seen any other API's but this is what i have read on other posts. 我还没有看到任何其他API,但这是我在其他帖子上看到的。

The problem here is first PDFBox i read that PDFBox can not be use because of AWT Dependencies and android is has no AWT and Swing related classes. 这里的问题首先是PDFBox我读到PDFBox因为AWT依赖而无法使用而且android没有AWT和Swing相关的类。 PDFBox is out of the question. PDFBox是不可能的。 muPDF i have not read anything about muPDF, it was recommended to me but i want to know if it is usable to read PDF Document. muPDF我还没有读过有关muPDF的任何内容,我向你推荐但我想知道它是否可用于阅读PDF文档。 iText this is the most common API that i encounter in PDF and android related questions. iText这是我在PDF和Android相关问题中遇到的最常见的API。 the problem here is its License ?(Correct me if im wrong) I have not tried any of this 3 yet because i want know if there are another solutions beside this 3. 这里的问题是它的许可证 ?(纠正我,如果我错了)我还没有尝试过这3个中的任何一个,因为我想知道这3之外是否还有其他解决方案。

Other than APIs, i think PDF Reader Applications can be used too if im not mistaken? 除了API,我认为PDF阅读器应用程序也可以使用,如果我没有弄错的话? if it can be used then HOW? 如果它可以使用然后如何? . I'm not looking for a Code but a explanation of how you did it and how you implemented it in your application. 我不是在寻找代码,而是在解释你是如何做到的以及如何在应用程序中实现它。

i have thought another way but i do not know if this is possible. 我想到了另一种方式,但我不知道这是否可行。 how about convert PDF Document into a .txt or .doc file? 如何将PDF文档转换为.txt或.doc文件? inside the android. 在android里面。 it would be like when i load a PDF document inside the android a Code will convert that PDF Document into a .txt / .doc file and the application will search and extract text from the .txt / .doc file rather then the PDF Document. 就像当我在android中加载PDF文档时,Code会将该PDF文档转换为.txt / .doc文件,应用程序将从.txt / .doc文件中搜索和提取文本,而不是PDF文档。

if you are asking WHY do i need this kind of component, because i'm working on a application that would SEARCH and EXTRACT text from a PDF Document using Android. 如果你问为什么我需要这种组件,因为我正在开发一个应用程序,可以使用Android从PDF文档中搜索提取文本。

This is my questions: 这是我的问题:

  1. What are the ways to read a PDF Document in Android? 在Android中阅读PDF文档的方法有哪些?
  2. What are your experiences in using this kind of method? 您使用这种方法有哪些经验?
  3. How did you do it using this kind of method(just a flow/explanation would do)? 你是怎么用这种方法做的(只是流程/解释会这样做)?
  4. If the method has a License what would be the problem in the future? 如果该方法具有许可证,将来会出现什么问题?

PS: Correct me if i'm wrong. PS:如果我错了,请纠正我。

Thank you. 谢谢。

This is a very iText specific answer so it does not answer all your questions, but it may still be of help to you. 这是一个非常iText的具体答案,因此它不能回答您的所有问题,但它可能仍然对您有所帮助。

What are the ways to read a PDF Document in Android? 在Android中阅读PDF文档的方法有哪些?

I use the iText java bindings (Keep reading to find out about LGPL licensing) 我使用iText java绑定(继续阅读以了解LGPL许可)

What are your experiences in using this kind of method? 您使用这种方法有哪些经验?

Great! 大! It covers all things PDF related. 它涵盖了与PDF相关的所有内容。 (Older versions may be a little different) (较旧版本可能略有不同)

How did you do it using this kind of method(just a flow/explanation would do)? 你是怎么用这种方法做的(只是流程/解释会这样做)?

I assume this question is related to the "other way" that you thought of so it is not relevant to the iText PDF library? 我假设这个问题与您想到的“其他方式”有关,因此它与iText PDF库无关?

If the method has a License what would be the problem in the future? 如果该方法具有许可证,将来会出现什么问题?

I still encourage you to use the updated version of iText, however if you use iText version 2.1.7 or older it falls under the old LGPL license, and has far more free reign and is more suitable for commercial or private/closed use with no real problems. 我仍然鼓励你使用iText的更新版本,但是如果你使用的是iText 2.1.7或更早的版本,它属于旧的LGPL许可证,并且有更多的免费统治,更适合商业或私人/封闭使用,没有真正的问题。 From what I can tell all the functionality you are after is available in version 2.1.7 version. 据我所知,您所使用的所有功能在2.1.7版本中都可用。

The AGPL license for current version of iText is pretty decent, from what I understand you do need to publish your program under a similar license and make the code freely available to others (it would pay to check the details though), if sharing code is not a problem then the latest version of iText is worth looking into. 当前版本的iText的AGPL许可证非常不错,根据我的理解,您需要在类似的许可下发布您的程序并使代码免费提供给其他人(如果共享代码是不是问题,因此最新版的iText值得研究。


References: 参考文献:

LGPL License: http://www.gnu.org/licenses/lgpl.html LGPL许可证: http//www.gnu.org/licenses/lgpl.html

iText AGPL License: http://itextpdf.com/terms-of-use/agpl.php iText AGPL许可证: http//itextpdf.com/terms-of-use/agpl.php

I was also working on an Android Application, where i need to open PDF files in my android application. 我还在开发Android应用程序,我需要在我的Android应用程序中打开PDF文件。 First i thought about doing this by using foreign API's. 首先,我想通过使用外国API来做到这一点。 I tried to used mupdf, but it was not a good experience. 我试过用mupdf,但这不是一个好的经历。

Then our team leader suuggested me to first install a pdf viewer application in your device and then use code to open pdf through the installed pdf viewer application. 然后我们的团队负责人建议我首先在您的设备中安装pdf viewer应用程序,然后使用代码通过已安装的pdf viewer应用程序打开pdf。

You can easily download pdf viewer application from gogle play, then you can use the following code to open the pdf in your application, 您可以从gogle play轻松下载pdf viewer应用程序,然后您可以使用以下代码在您的应用程序中打开pdf,

                File file = new File("/sdcard/MyPDFfile.pdf");
                Uri path = Uri.fromFile(file);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(path, "application/pdf");
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);

This code will automatically look for the installed pdf application in your device and will pass the intent to that application to open the pdf file. 此代码将自动在您的设备中查找已安装的pdf应用程序,并将意图传递给该应用程序以打开pdf文件。

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

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