I am trying to open a link to a pdf file and display the pdf when a button is clicked on the device. What is the best way to go about this? I would like to be able to not use a 3rd party software. So I know that I might have to convert the file to something else.
Asked
Active
Viewed 4,368 times
0
-
Take a look at [this][1] quiestion, hope this helps. [1]: http://stackoverflow.com/questions/3530780/android-is-there-any-free-pdf-library-for-android – ilya.stmn Jun 04 '13 at 03:14
-
you can try with this..https://github.com/bitfield66/PdfViewerAndroid_Offline – user2361120 Dec 04 '13 at 10:25
-
The easiest way is to simply load the pdf using Google docs viewer. This way it can be done in a web view. But the downside is there is not a lot of functionality. – bigC5012 Sep 30 '14 at 02:39
2 Answers
1
Try this inside your Button's click listener:
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),”application/pdf”);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
You should check if any PDF reading application is available before using this code.
If you are planning to implement your own PDF reader then refer this.
0
I think you should create your own pdf Reader For that u have to download PDF VIEWER.jar then try this code
MainActivity.java
public class MainActivity 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(MainActivity.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.ic_launcher;
}
public int getNextPageImageResource() {
return R.drawable.ic_launcher;
}
public int getZoomInImageResource() {
return R.drawable.ic_launcher;
}
public int getZoomOutImageResource() {
return R.drawable.ic_launcher;
}
public int getPdfPasswordLayoutResource() {
return R.drawable.ic_launcher;
}
public int getPdfPageNumberResource() {
return R.drawable.ic_launcher;
}
public int getPdfPasswordEditField() {
return R.drawable.ic_launcher;
}
public int getPdfPasswordOkButton() {
return R.drawable.ic_launcher;
}
public int getPdfPasswordExitButton() {
return R.drawable.ic_launcher;
}
public int getPdfPageNumberEditField() {
return R.drawable.ic_launcher;
}
}

RINK
- 620
- 5
- 15