我在API 5.0上使用PDFRenderer创建一个应用程序我不得不在外部添加pdf渲染器.jar现在它也显示以下错误 - "构造函数 PDFRenderer(ParcelFileDescriptor) 未定义"谁能帮忙...这对我来说是新的..
使用 PDFRenderer(ParcelFileDescriptor input)
其中输入是可查找的文件描述符。
Pdf 渲染器基本上将文件描述符作为其参数,而您没有提供任何描述符。
请参阅开发人员页面https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html
private void render() {
try {
Log.e("In render()","render");
imageView = (ImageView) findViewById(R.id.imageView);
int REQ_WIDTH = 1;
int REQ_HEIGHT = 1;
REQ_WIDTH = imageView.getWidth();
REQ_HEIGHT = imageView.getHeight();
Log.e("In render2()","render2");
System.out.println("req_height"+REQ_HEIGHT+" "+"REQ_WIDTH"+REQ_WIDTH);
Bitmap bitmap = Bitmap.createBitmap(REQ_WIDTH, REQ_HEIGHT, Bitmap.Config.ARGB_4444);
File file = new File("/home/woigames/Desktop/PDF/DebitCards-tc.pdf");
PDFRenderer renderer = new PDFRenderer(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY));
if(renderer != null)
{
Log.i("renderer not null","check");
}
else
{
Log.i("renderer is null","check");
}
final int pageCount = renderer.getPageCount();
if (currentPage < 0) {
currentPage = 0;
} else if (currentPage > renderer.getPageCount()) {
currentPage = renderer.getPageCount() - 1;
}
Matrix m = imageView.getImageMatrix();
Rect rect = new Rect(0, 0, REQ_WIDTH, REQ_HEIGHT);
renderer.openPage(currentPage).render(bitmap, rect, m, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
imageView.setImageMatrix(m);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
renderer.close();
} catch (Exception e) {
e.printStackTrace();
}
在清单中添加 API 级别 21 并尝试 .Lolipop pdf 渲染器需要最低 SDK 级别 21
<uses-sdk android:minSdkVersion="21" />