public void createPDF() {
Document doc = new Document();
try {
path = Environment.getExternalStorageDirectory().getAbsolutePath() + \"/ADUREC\";
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
Log.d(\"PDFCreator\", \"PDF Path: \" + path);
//This is for random name
number = new ArrayList();
for (int i = 1; i <= 10; ++i) number.add(i);
Collections.shuffle(number);
File file = new File(dir, \"Document\" + number + \".pdf\");
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
//open the document
doc.open();
Paragraph p1 = new Paragraph(\"TENANTS : \" + tenants.getText().toString());
Font paraFont = new Font(Font.COURIER);
p1.setAlignment(Paragraph.ALIGN_CENTER);
p1.setFont(paraFont);
//add paragraph to document
doc.add(p1);
Paragraph p2 = new Paragraph(\"OFFFER NUMBER : \" + offer_number.getText().toString());
Font paraFont2 = new Font(Font.COURIER, 14.0f, Color.GREEN);
p2.setAlignment(Paragraph.ALIGN_CENTER);
p2.setFont(paraFont2);
doc.add(p2);
Paragraph p3 = new Paragraph(\"OFFFER NUMBER : \" + offer_number.getText().toString());
Font paraFont3 = new Font(Font.COURIER, 14.0f, Color.GREEN);
p3.setAlignment(Paragraph.ALIGN_CENTER);
p3.setFont(paraFont2);
doc.add(p3);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.logo);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.setAlignment(Image.MIDDLE);
// add image to document
doc.add(myImg);
//set footer
Phrase footerText = new Phrase(\"ADUREC DOCUMENT\");
HeaderFooter pdfFooter = new HeaderFooter(footerText, true);
doc.setFooter(pdfFooter);
// Toast.makeText(getApplicationContext(), \"success pdf\", Toast
// .LENGTH_LONG).show();
} catch (DocumentException de) {
Log.e(\"PDFCreator\", \"DocumentException:\" + de);
} catch (IOException e) {
Log.e(\"PDFCreator\", \"ioException:\" + e);
} finally {
doc.close();
}
}