Create and save pdf file to external storage
I want to create a PDF file when i select an item from list and save that
row value as PDF format in my external storage. Please help me.
What i tried so far:
String data;
ListView listView;
listView= (ListView) findViewById(R.id.listView);
listView.setOnClickListener(new View.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
// Save PDF code here
data = listView.getItemAtPosition(0).toString();
Document document = new Document();
try {
File temp = new
File(Environment.getExternalStorageDirectory().getAbsolutePath(),"abcd.pdf");
PdfWriter.getInstance(document,
new FileOutputStream(temp));
document.open();
document.addSubject(data);
document.close();
Toast.makeText(getApplicationContext(),
"PDF Saved",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"PDF cannot Saving",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
break;
case 1:
// Share code here
Toast.makeText(getApplicationContext(),
"Your Doc is Sharing...",
Toast.LENGTH_SHORT).show();
break;
}
}
});
No comments:
Post a Comment