PDF Library to Rendering the PDF Files in Android

Android PDF Rendering

I've done some research in this field recently, I've tried more than 14 libraries on Android, I've done simple benchmarking on some high resolution print-ready PDF magazines and I'm currently considering to use MuPDF or Radaee in work as they went out as the best.

I've tried VuDroid and apv as well and they are very unstable, they are crashing very often on complex PDF documents and very slow in comparsion to MuPDF or Radaee.

Since MuPDF and Radaee (and some other libraries) are written in pure C and are used on Android through NDK, they are giving the best possible performance (and they both are paid for a commercial use).

which library to use for displaying PDF file in application?

  1. Qoppa is commercial product
  2. muPDF is lightweight but GPLed
  3. iText is AGPLed, a tailored GPL v3.
  4. pdfBox is good but a bit big in size.

How to render PDF in Android

Some phones (like the Nexus One) come with a version of Quickoffice pre-installed so it may be as easy as sending the appropriate Intent once you've saved the file to the SD card.

public class OpenPdf extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button button = (Button) findViewById(R.id.OpenPdfButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File file = new File("/sdcard/example.pdf");

if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(OpenPdf.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
}
});
}
}


Related Topics



Leave a reply



Submit