private void saveDataInPDF(List<ContactDetail> calllist, String filename) {
Document doc = new Document();
try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Dir";
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
File file = new File(dir,filename);
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
//open the document
doc.open();
Paragraph p1=null;
for(int i=0;i<calllist.size();i++) {
ContactDetail contactDetail=calllist.get(i);
p1 = new Paragraph(contactDetail.getCalltype()+""+contactDetail.getMobilenumber());
doc.add(p1);
}
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
} finally {
doc.close();
}
viewPdf(filename, "Dir");
}
//////////////////////viewpdf
private void viewPdf(String file, String directory) {
try {
File pdfFile = new File(Environment.getExternalStorageDirectory() + "/" + directory + "/" + file);
Uri path = Uri.fromFile(pdfFile);
Log.e("Path", path.toString());
Intent objIntent = new Intent(Intent.ACTION_VIEW);
objIntent.setDataAndType(path, "application/pdf");
objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_SUBJECT, directory);
email.putExtra(Intent.EXTRA_TEXT, file);
email.setType("application/pdf");
email.putExtra(Intent.EXTRA_STREAM, path);
startActivity(Intent.createChooser(email, "Send Mail..."));
//sendMail(path);
}
catch (ActivityNotFoundException e) {
Toast.makeText(ContactRestore.this, "Can't Read Pdf File", Toast.LENGTH_SHORT).show();
}
}
Document doc = new Document();
try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Dir";
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
File file = new File(dir,filename);
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
//open the document
doc.open();
Paragraph p1=null;
for(int i=0;i<calllist.size();i++) {
ContactDetail contactDetail=calllist.get(i);
p1 = new Paragraph(contactDetail.getCalltype()+""+contactDetail.getMobilenumber());
doc.add(p1);
}
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
} finally {
doc.close();
}
viewPdf(filename, "Dir");
}
//////////////////////viewpdf
private void viewPdf(String file, String directory) {
try {
File pdfFile = new File(Environment.getExternalStorageDirectory() + "/" + directory + "/" + file);
Uri path = Uri.fromFile(pdfFile);
Log.e("Path", path.toString());
Intent objIntent = new Intent(Intent.ACTION_VIEW);
objIntent.setDataAndType(path, "application/pdf");
objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_SUBJECT, directory);
email.putExtra(Intent.EXTRA_TEXT, file);
email.setType("application/pdf");
email.putExtra(Intent.EXTRA_STREAM, path);
startActivity(Intent.createChooser(email, "Send Mail..."));
//sendMail(path);
}
catch (ActivityNotFoundException e) {
Toast.makeText(ContactRestore.this, "Can't Read Pdf File", Toast.LENGTH_SHORT).show();
}
}
No comments:
Post a Comment