KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need to convert PDFfile(PDF page) into a Bitmap(or Image file) in Android. 1.Used Pdfbox jar from Apache. But it uses some java classes that is not supported in android. 2. Tried Itext jar which converts image to pdf(I need its reverse operation) Like that I have tried many jars. But no positive result. 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); I am getting the Image File, Instead of, package com.test123; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import com.sun.pdfview.PDFFile;
Tags (comma-separated)
Save Edits
Cancel