Note that there are some explanatory texts on larger screens.

plurals
  1. POExample of code to implement a PDF reader
    primarykey
    data
    text
    <p>I want to implement a PDF reader in the application that I am doing, I have found several APIs, but none of them were open source. </p> <p>Does any of you guys know a good free alternative?</p> <hr> <h2>Slight adaptation of <a href="https://stackoverflow.com/a/11153601/505893">Dipak Keshariya's solution</a> made by the OP</h2> <p><strong>First Class</strong></p> <pre><code>package android.pdf.reader; import java.io.File; import java.io.FilenameFilter; import net.sf.andpdf.pdfviewer.PdfViewerActivity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Environment; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class First extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); File images = Environment.getExternalStorageDirectory(); File[] imagelist = images.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return ((name.endsWith(".pdf"))); } }); String[] pdflist = new String[imagelist.length]; for(int i = 0;i&lt;imagelist.length;i++) { pdflist[i] = imagelist[i].getName(); } this.setListAdapter(new ArrayAdapter&lt;String&gt;(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); Object[] imagelist; String path = ((File) 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(); } } } </code></pre> <p><strong>Secod Class</strong></p> <pre><code>package android.pdf.reader; import net.sf.andpdf.pdfviewer.PdfViewerActivity; import android.os.Bundle; 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; } } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload