Videos
More about PdfActivity
PdfActivity is a public class that extends AppCompatActivity(opens in a new tab) and implements [PdfUi], [PdfActivityListener], and PdfActivityComponentsApi. It’s an activity with fully integrated views and behavior, and it can be invoked by the simple helper methods [showDocument][showdocument]) and [showImage][showimage]).
What is an intent in Android?
Intents are messages you pass to the Android OS. They describe actions you want the system to perform on your behalf. After describing an intent, you pass it to the OS and act on the result. Usually, the result is passed to a callback function.
What’s a request code used for in Android?
In Android, request codes help identify intents and their corresponding results. The best place to declare a request code is in a separate file that holds all your constants.
I'd recommend considering MuPDF which has already been ported for use on Android several times without reliance on Java. MuPDF is optimized for lightweight on-screen PDF rendering, making it perfect for mobile use.
Please note that MuPDF and all the derived projects are not suitable for the commercial use and you should consider alternatives if you are not developing an open source GPL project.
You will need pdf parsing libraries in JAVA... Parse the document, and display content in android. Below are some useful links :
http://java-source.net/open-source/pdf-libraries
http://itextpdf.com/
http://itextpdf.com/examples/iia.php?id=275
Advanced PDF parser for Java
Use below code for that.
First.java
public class First extends ListActivity {
String[] pdflist;
File[] imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Second.java
public class Second extends PdfViewerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public int getPreviousPageImageResource() {
return R.drawable.left_arrow;
}
public int getNextPageImageResource() {
return R.drawable.right_arrow;
}
public int getZoomInImageResource() {
return R.drawable.zoom_in;
}
public int getZoomOutImageResource() {
return R.drawable.zoom_out;
}
public int getPdfPasswordLayoutResource() {
return R.layout.pdf_file_password;
}
public int getPdfPageNumberResource() {
return R.layout.dialog_pagenumber;
}
public int getPdfPasswordEditField() {
return R.id.etPassword;
}
public int getPdfPasswordOkButton() {
return R.id.btOK;
}
public int getPdfPasswordExitButton() {
return R.id.btExit;
}
public int getPdfPageNumberEditField() {
return R.id.pagenum_edit;
}
}
And declared both activities into your manifest file.
There is a very good post about this on SO. In particular check out the answer given by Commons.Ware, it answers your question.
Following your comments I have added the links here from the SO post I mentioned above (source for projects you could not find):
- Android-Pdf-Viewer-Library (hosted at Github)
- APV (hosted at Google code, uses Mercurial)
- Android PDF Viewer (hosted at Sourceforge, uses SVN)
So "checkout" or clone the repositories to your local file system to browse the code. As I mentioned in my comment check the licence of each library before you go any further to see if what you can and cannot do with the code.