我正在尝试将android活动转换为pdf文件,以便它可以作为邮件发送。这是我试过的代码..我无法获得pdf !!! Plz帮助..
public void createPdf() throws FileNotFoundException, DocumentException {
String dir = Environment.getExternalStorageDirectory() + File.separator + "myLogs";
File folder = new File(dir);
folder.mkdirs();
DatabaseHandler dbHandler = new DatabaseHandler(this);
File file = new File(dir, "Facility_data.pdf");
SQLiteDatabase database = dbHandler.getReadableDatabase();
Cursor c1 = database.rawQuery("SELECT * FROM " + DatabaseHandler.TABLE_NAME, null);
Document document = new Document(); // create the document
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
Paragraph p3 = new Paragraph();
p3.add("Username :");
document.add(p3);
PdfPTable table = new PdfPTable(2);
table.addCell("NAME :");
table.addCell("REP :");
while (c1.moveToNext()) {
String user_name = c1.getString(1);
String rep_name = c1.getString(2);
/* String date = c1.getString(3);
String start = c1.getString(1);
String end = c1.getString(2);
String total = c1.getString(4);*/
table.addCell(user_name);
table.addCell(rep_name);
//table.addCell(end);
//table.addCell(total);
}
document.add(table);
document.addCreationDate();
document.close();
}