2015-05-29 174 views
1

我使用Google搜索,但找不到解决方案来执行此操作。使用mupdf将Pdf页转换为图像

我需要从PDF的第一页显示图像缩略图视图而不打开它。 PDF文件将在我的手机中提供。

安装另一个外部库是不可能的。 Mupdf可用。

+0

使用muPDF是重要的,还是以任何方式将第一页转换为图像足够? –

+0

@ user1587329没关系。根本没有问题。但我无法切换任何其他库来渲染。 ..感谢 –

+0

无法打开PDF文件的第一页,而无需打开PDF文件.... – KenS

回答

2

如果你想不用muPDF做到这一点,看看How to convert a PDF page to an image in Android?second answer给出了链接PdfRenderer(API 21提供)。你可能会使用这样的:

// create a new renderer 
PdfRenderer renderer = new PdfRenderer(getSeekableFileDescriptor()); 

// render the page 
Page page = renderer.openPage(i).render(mBitmap, null, null, Page.RENDER_MODE_FOR_DISPLAY); 

// do stuff with the bitmap 

// close the page 
page.close(); 

// close the renderer 
renderer.close(); 
2

最后我做到了这一点,通过

一个DrawPage(BP,0,size.x,size.y,0,0,size.x ,size.y,new Cookie());

它将帮助您将PDF的第一页呈现为BitMap。这个方法在MuPDFCore.java中实现。

PointF pageSize = getPageSize(0); float mSourceScale = Math.max(w/pageSize.x,h/pageSize.y);

 Point size = new Point((int)(pageSize.x*mSourceScale), (int)(pageSize.y*mSourceScale)); 
     final Bitmap bp = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); 

     drawPage(bp, 0, size.x, size.y, 0, 0, size.x, size.y, new Cookie()); 
     storeImageIntoLocal(bp,filePath);//To Do my custom method to store bitmap into local