I'm new in Android . I'm implementing PDF document using iText in Android . I want to read PDF document in my application. I don't have an idea how to access PDF doc in my app. I have created but when I run the application I get exception for FileNotFoundException
and I also import a PDF file in SD card through DD-MS. But the PDF file does not open in Android. Here is my code:
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.codec.Base64.InputStream;
public class MainActivity extends Activity
{
private static String FILE = "xyz.pdf";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AssetManager assetManager = getAssets();
InputStream istr = null;
PdfReader reader = null;
String str = null;
int n = 0;
try
{
istr =(InputStream) assetManager.open("xyz.pdf");
reader=new PdfReader(istr);
n=reader.getNumberOfPages();
Log.e("n value:","-> " +n);
str=reader.getPageContent(2).toString();
}
catch(Exception e)
{
e.printStackTrace();
}
TextView tv = (TextView) findViewById(R.id.textOne);
tv.setText(str);
}
}