拇指来自pdf android

  • 本文关键字:pdf android android pdf
  • 更新时间 :
  • 英文 :


我想在我的应用程序中显示pdf的拇指图像。我使用这个答案。但我不知道如何在android中使用它,因为矩形2d不能在java中使用。我尝试使用rectand修改代码为:

 File file = new File(arrayOfResults.get(arg0).filePath);
 RandomAccessFile raf = new RandomAccessFile(file, "r");
                FileChannel channel = raf.getChannel();
                ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
                        0, channel.size());
                PDFFile pdffile = new PDFFile(buf);
                // draw the first page to an image
                PDFPage page = pdffile.getPage(0);
                // get the width and height for the doc at the default zoom
                RectF rect = new RectF(0, 0, (int) page.getWidth(),
                        (int) page.getHeight());

但是应用程序崩溃了,出现以下错误:

java.lang.NoClassDefFoundError: java.awt.geom.Rectangle2D$Double
at com.sun.pdfview.PDFFile.parseNormalisedRectangle(PDFFile.java:1874)

请帮。

Android在API 21中增加了PdfRenderer类。

如果你需要低于这个标准,你需要自带PDF渲染引擎。我们查看了市场,发现所有的选择都以这样或那样的方式缺乏,并为Android创建了PSPDFKit。这是一个商业PDF框架,(完全免责声明)我是构建它的团队的一员。

在PSPDFKit for Android中,你可以使用renderPageToBitmap将PDF渲染成位图

如果你的项目是个人项目,或者你是个独立开发者,可以试试http://plugpdf.com/他们为你免费提供Android PDF SDK。你也可以看看他们关于在Android上将PDF页面转换为位图图像的博客文章。http://plugpdf.com/how-to-render-a-pdf-document-to-bitmap-image-on-android/

免责声明:我是创始人&ePapyrus公司首席执行官,该公司运营plugpdf.com。

最新更新