如何获取Android中pdf文件的页数? [英] How to get the number of pages of a pdf file in Android?
本文介绍了如何获取Android中pdf文件的页数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您能帮我找出Android上pdf文档的页数吗,至少支持api版本16. .到目前为止,这是我要做的事情:
Can you help me find out the number of pages of a pdf document on Android, that will support down to at least api version 16. I am extracting document information but can't see a solution to get the total amount of pages. This Is what I doo so far:
private void extractDocumentDataFromUri(Uri uri)
{
String[] dataFileds = new String[]{
MediaStore.MediaColumns.DATA,
OpenableColumns.DISPLAY_NAME,
OpenableColumns.SIZE};
Cursor cursor = context.getContentResolver().query(uri, dataFileds, null, null, null);
cursor.moveToFirst();
contentUrl = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));
title = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
size = cursor.getInt(cursor.getColumnIndex(OpenableColumns.SIZE));
cursor.close();
contentType = context.getContentResolver().getType(uri);
}
推荐答案
如果将iTextG库添加到libs文件夹,则此解决方案有效.该库包含一个名为 PdfReader 的类.
This solution works if you add the iTextG library to your libs folder. The library contains a class called PdfReader.
尝试这样的事情:
PdfReader reader = new PdfReader("Your file path");
int aa = reader.getNumberOfPages();
这篇关于如何获取Android中pdf文件的页数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文