將Pdf頁面轉(zhuǎn)換為Android Java中的Bitmap我需要將PDF文件(PDF頁面)轉(zhuǎn)換為Android中的位圖(或圖像文件)。1.使用Apache的Pdfbox jar。但是它使用了android中不支持的一些java類。2.嘗試將圖像轉(zhuǎn)換為pdf的Itext jar(我需要它的反向操作)就像我嘗試了很多罐子一樣。但沒有積極的結(jié)果。byte[] bytes;
try {
File file = new File(this.getFilesDir().getAbsolutePath()+"/2010Q2_SDK_Overview.pdf");
FileInputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
bytes = new byte[(int) length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
ByteBuffer buffer = ByteBuffer.NEW(bytes);
String data = Base64.encodeToString(bytes, Base64.DEFAULT);
PDFFile pdf_file = new PDFFile(buffer);
PDFPage page = pdf_file.getPage(2);
RectF rect = new RectF(0, 0, (int) page.getBBox().width(),
(int) page.getBBox().height());
// Bitmap bufferedImage = Bitmap.createBitmap((int)rect.width(), (int)rect.height(),
// Bitmap.Config.ARGB_8888);
Bitmap image = page.getImage((int)rect.width(), (int)rect.height(), rect);
FileOutputStream os = new FileOutputStream(this.getFilesDir().getAbsolutePath()+"/pdf.jpg");
image.compress(Bitmap.CompressFormat.JPEG, 80, os);
// ((ImageView) findViewById(R.id.testView)).setImageBitmap(image);否則,使用內(nèi)置在應(yīng)用程序中的函數(shù)在android中顯示pdf文件的任何其他方式?
- 4 回答
- 0 關(guān)注
- 1454 瀏覽
添加回答
舉報
0/150
提交
取消