java 适用于 Android 的 PDF 查看器 API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14289156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PDF Viewer API for android
提问by Christian Eric Paran
Possible Duplicate:
Example of code to implement a PDF reader
可能的重复:
实现 PDF 阅读器的代码示例
Is there a Free PDF Viewer that I can use for my Application?
是否有免费的 PDF 查看器可以用于我的应用程序?
I am looking for a PDF Viewer that can search, highlight text, view the page that user wants, and without altering the contents of the PDF file. Just like Adobe Reader but for Android that can be implemented to a Application.
我正在寻找一个 PDF 查看器,它可以搜索、突出显示文本、查看用户想要的页面,而无需更改 PDF 文件的内容。就像 Adobe Reader 但适用于可以实现到应用程序的 Android。
You can link me to a same question or source code.
您可以将我链接到相同的问题或源代码。
EDIT:
编辑:
I have found this question "Pdf viewer api/library for android app sample code?" but I think his looking for a Reader. this question "pdf viewer library for android" I read that to view pdf it should be Natively and the solution for that is to use External Applications.
我发现了这个问题“ Android 应用程序示例代码的 Pdf viewer api/library?”但我认为他正在寻找Reader。这个问题“ android的pdf查看器库”我读到它应该是本机的pdf查看器,解决方案是使用外部应用程序。
If I use external application, I want the external application accepts PDF Filepath, Page to view, and Keyword for search programmatically but i think external application wont let me do that.
如果我使用外部应用程序,我希望外部应用程序以编程方式接受 PDF 文件路径、要查看的页面和用于搜索的关键字,但我认为外部应用程序不会让我这样做。
采纳答案by Dipak Keshariya
Use Below Code for Read PDF using PDFViewer.jar library, it will solve your problem.
使用以下代码使用 PDFViewer.jar 库读取 PDF,它将解决您的问题。
First.java
首先.java
public class First extends ListActivity {
String[] pdflist;
File[] imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Second.java
第二个.java
public class Second extends PdfViewerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public int getPreviousPageImageResource() {
return R.drawable.left_arrow;
}
public int getNextPageImageResource() {
return R.drawable.right_arrow;
}
public int getZoomInImageResource() {
return R.drawable.zoom_in;
}
public int getZoomOutImageResource() {
return R.drawable.zoom_out;
}
public int getPdfPasswordLayoutResource() {
return R.layout.pdf_file_password;
}
public int getPdfPageNumberResource() {
return R.layout.dialog_pagenumber;
}
public int getPdfPasswordEditField() {
return R.id.etPassword;
}
public int getPdfPasswordOkButton() {
return R.id.btOK;
}
public int getPdfPasswordExitButton() {
return R.id.btExit;
}
public int getPdfPageNumberEditField() {
return R.id.pagenum_edit;
}
}
And Declared Both Activities into your manifest file.
并将两个活动声明到您的清单文件中。
回答by Gabe Sechan
If you want an API, I don't think there are any free ones. I recently had to build one into an app for my employer, we ended up having a choice of 3 paid libraries, the cheapest of which was around $1K/app. If you just want to launch it in an external app, you can download a free one and launch the view intent on the file.
如果你想要一个 API,我认为没有任何免费的。我最近不得不为我的雇主构建一个应用程序,我们最终可以选择 3 个付费图书馆,其中最便宜的大约 1000 美元/应用程序。如果您只想在外部应用程序中启动它,您可以下载一个免费的应用程序并在文件上启动查看意图。