我使用了许多库,但这些都是无用的,我还检查了PDF文件是否可以在web视图中打开,通过使用 contentprovider 将我的URI转换为Html代码,但这也不适合我。
我使用过像
这样的库- PDF查看器 <
- MuPDF库/strong>
- 和更多…
所以,如果有人遇到这个问题或有解决这个问题的方法,请帮助我解决这个问题。
我使用PDFViewer库PDFViewer解决了这个问题你所需要做的就是:
- 导入PDFViewer项目到您的工作区(或使用PDFViewer)。jar文件)。 将其添加为项目库。
像这样定义一个活动:
public class ViewerActivity extends PdfViewerActivity { 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; }
}
呼叫活动如下:
Intent intent = new Intent(this, MainActivity.class); intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, FILE_PATH); startActivity(intent);
其中FILE_PATH是设备上的pdfFileLocation。我的是
final String FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test/com_handbook.pdf";