• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to read a pdf using itext library in android

Hi,
I am a newbie in android world. I tired to create a android project using eclipse IDE, in which i tried reading a pdf file with the help of itext library.
This pgm is not showing any output.Please tell me how to correct the code,so that i can extract the text from pdf file stored in Assets folder in the project.


The program code is given as :
Code:
public class hello extends Activity {
    /** Called when the activity is first created. */
    public static final String LOG_TAG="Fifth";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        AssetManager assetManager =getAssets();
        InputStream istr = null;
        PdfReader reader=null;
        String str=null;
        int n=0;
        try {
            istr =(InputStream) assetManager.open("FirstPdf");
       
            
             reader=new PdfReader(istr);
             n=reader.getNumberOfPages();
            Log.v(LOG_TAG,"n value:" +n);
         str=reader.getPageContent(2).toString();
        } 
        catch (Exception e)
        {
            e.printStackTrace();
        }  
       
        TextView tv = new TextView(this);
        tv.setText(n);
        setContentView(tv);
    }
}

Regards
Thomas
 
Back
Top Bottom