是否有任何兼容的android庫將PDF頁面轉換爲圖像?我發現了幾個適合我需求的java庫(pdfbox,jpod,jpedal,icepdf),但他們給我編譯錯誤(基於awT或swt)。我目前正在android上製作pdf查看器,如果我不必從頭開始編寫pdf解碼,我會很棒。用於從pdf文件創建圖像的Android兼容庫?
回答
最好的辦法是這個庫:http://code.google.com/p/apv/
這是一個C項目,所以你需要使用JNI調用。
這是基於MuPDF這是AGPL許可證,並不完全兼容商業軟件。只是FYI ... – startoftext 2014-12-12 21:04:00
感謝您的幫助。我檢查了項目並使用了MuPDF庫(APV項目基於此庫)。它工作正常!非常感謝上帝保佑。
使用itextpdf5.3.1.jar
下面是從PDF提取圖像的代碼:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);`enter code here`
PdfReader reader;
File file = new File("/sdcard/vineeth/anni.prc");
try{
reader = new PdfReader(file.getAbsolutePath());
for (int i = 0; i < reader.getXrefSize(); i++) {
PdfObject pdfobj= reader.getPdfObject(i);
if (pdfobj == null || !pdfobj.isStream()) {
continue;
}
PdfStream stream = (PdfStream) pdfobj;
PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE);
if (pdfsubtype != null && pdfsubtype.toString().equals(PdfName.IMAGE.toString())) {
byte[] img = PdfReader.getStreamBytesRaw((PRStream) stream);
FileOutputStream out = new FileOutputStream(new
File(file.getParentFile(),String.format("%1$05d", i) + ".jpg"));
out.write(img); out.flush(); out.close();
}
}
} catch (Exception e) { }
}
你應該提供一些解釋和代碼。 – 2012-10-01 18:04:53
上面的代碼僅包含pdf中的_extracts_圖像,它不會生成PDF文件的圖像。 – Minsky 2014-08-07 08:16:34
以上答案都不幫我,所以我寫我的解決方案。
使用這個庫:android-pdfview和下面的代碼,就可以可靠地轉換的PDF頁面轉換成圖片(JPG,PNG):
DecodeServiceBase decodeService = new DecodeServiceBase(new PdfContext());
decodeService.setContentResolver(mContext.getContentResolver());
// a bit long running
decodeService.open(Uri.fromFile(pdf));
int pageCount = decodeService.getPageCount();
for (int i = 0; i < pageCount; i++) {
PdfPage page = decodeService.getPage(i);
RectF rectF = new RectF(0, 0, 1, 1);
// do a fit center to 1920x1080
double scaleBy = Math.min(AndroidUtils.PHOTO_WIDTH_PIXELS/(double) page.getWidth(), //
AndroidUtils.PHOTO_HEIGHT_PIXELS/(double) page.getHeight());
int with = (int) (page.getWidth() * scaleBy);
int height = (int) (page.getHeight() * scaleBy);
// you can change these values as you to zoom in/out
// and even distort (scale without maintaining the aspect ratio)
// the resulting images
// Long running
Bitmap bitmap = page.renderBitmap(with, height, rectF);
try {
File outputFile = new File(mOutputDir, System.currentTimeMillis() + FileUtils.DOT_JPEG);
FileOutputStream outputStream = new FileOutputStream(outputFile);
// a bit long running
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
} catch (IOException e) {
LogWrapper.fatalError(e);
}
}
你應該通過使用AsyncTask
或IE在後臺做這個工作類似於相當多的方法需要計算或IO時間(我在註釋中標記了它們)。
- 1. 創建圖像文件,android
- 2. 使用TCPDF從PDF創建圖像
- 3. 使用iText從TIFF圖像創建PDF
- 4. 創建CoRD兼容的RDP文件
- 5. 用圖像創建PDF
- 6. 用數據庫中的內容創建PDF文件
- 7. 從數據庫創建PDF和文件夾中的圖片
- 8. 用於創建.TMB圖像的庫?
- 9. Android試圖下載數據庫創建的圖像文件
- 10. iText是否創建基於圖像或基於文本的PDF文件?
- 11. onView使用兼容庫創建
- 12. 允許用戶創建PDF或圖像文件的Flash插件
- 13. 如何使用PDFBox for Android從tiff圖像創建PDF?
- 14. 從Excel創建PDF文件:問題與圖像
- 15. 適用於Android的GPL兼容圖形庫
- 16. iphone從pdf頁面創建PDF文件
- 17. 如何從Android中的圖像文件創建位圖
- 18. 從圖像列表中創建PDF
- 19. ImageMagick從圖像創建PDF版本1.4?
- 20. 用php創建圖像重pdf格式的文件
- 21. iPhone和Android中的圖像兼容性
- 22. 使用JQuery從PDF文件中提取圖像並創建縮略圖
- 23. 是否可以使用Coldfusion 8從PDF文件創建縮略圖圖像?
- 24. 使用內嵌圖像創建PDF文件(py)開羅
- 25. 如何從圖像創建數據量用於nginx容器
- 26. Android創建RSA 1024 .NET兼容密鑰
- 27. 添加圖像(PNG文件)到用R創建的pdf文件的標題
- 28. 如何從文件內容創建OpenCV圖像?
- 29. 創建PDF文件?
- 30. 使用itextsharp創建pdf與數據庫中的圖像
嘗試此:http://stackoverflow.com/a/16294833/2027232 – 2013-04-30 07:58:36