I'd like to create an eBook reader app for Android but in my case, all books are basically just scanned images compiled in PDF format.
But after a lot head banging and several开发者_高级运维 tests it turned out that PDF rendering on Android is awfully slow, especially on low-end devices.
So I'm wondering if theres a way to show these images directly instead of PDF but still show them as a "book", so technically an "image viewer" but the user doesn't notice. Is it possible?
I'd appreciate any help. Thanks!
PDF isn't made up of images, they're vectors, there's a way to convert that to image files.
There are a couple open-source java PDF to Image converters though like:
http://www.jpedal.org/
http://code.google.com/p/pdfonejava/
I'm sure there are more but you'll have to find them.
Then just cache those images and there are several open-source android image viewers like:
http://code.google.com/p/android-mysample-project/source/browse/trunk/ARCamera/src/net/android/sample/imageviewer/ImageViewer.java?spec=svn9&r=9
Is this what your aiming for or am I completely off?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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) {
// TODO: handle exception
}
}
精彩评论