我使用Google搜索,但找不到解決方案來執行此操作。使用mupdf將Pdf頁轉換爲圖像
我需要從PDF的第一頁顯示圖像縮略圖視圖而不打開它。 PDF文件將在我的手機中提供。
安裝另一個外部庫是不可能的。 Mupdf可用。
我使用Google搜索,但找不到解決方案來執行此操作。使用mupdf將Pdf頁轉換爲圖像
我需要從PDF的第一頁顯示圖像縮略圖視圖而不打開它。 PDF文件將在我的手機中提供。
安裝另一個外部庫是不可能的。 Mupdf可用。
如果你想不用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();
最後我做到了這一點,通過
一個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
使用muPDF是重要的,還是以任何方式將第一頁轉換爲圖像足夠? –
@ user1587329沒關係。根本沒有問題。但我無法切換任何其他庫來渲染。 ..感謝 –
無法打開PDF文件的第一頁,而無需打開PDF文件.... – KenS