זה הקוד של יצירת הקובץ
private void createPdf() {
String emailAddress[] = {transaction.getEmail(),company.getMail()};
createPDF();
File externalStorage = Environment.getExternalStorageDirectory();
Uri uri = Uri.fromFile(new File(externalStorage.getAbsolutePath() + "/PDF/okTransaction.pdf"));
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "OK Transaction");
emailIntent.putExtra(Intent.EXTRA_TEXT, transaction.getName());
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri );
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
}
public void createPDF()
{
Document doc = new Document();
try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/PDF";
File dir = new File(path);
if(!dir.exists())
dir.mkdirs();
Log.d("PDFCreator", "PDF Path: " + path);
File file = new File(dir, "okTransaction.pdf");
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
//open the document
doc.open();
/* Create Paragraph and Set Font */
Paragraph p1 = new Paragraph("אישור עסקה");
/* Create Set Font and its Size */
Font paraFont= new Font(Font.HELVETICA);
paraFont.setSize(16);
p1.setAlignment(Paragraph.ALIGN_CENTER);
p1.setFont(paraFont);
//add paragraph to document
doc.add(p1);
Paragraph p2 = new Paragraph(company.getUsername()+","+company.getMerchantNum());
paraFont= new Font(Font.HELVETICA);
paraFont.setSize(14);
p2.setAlignment(Paragraph.ALIGN_CENTER);
p2.setFont(paraFont);
doc.add(p2);
PdfPTable table=new PdfPTable (2);
table.setWidths(new float[]{2.6f, 2.6f});
Font font = new Font(Font.HELVETICA, 14, Font.BOLD, harmony.java.awt.Color.BLACK);
PdfPCell cell = new PdfPCell(new Phrase("HMKCODE.com - iText PDFTable Example",font));
cell.setColspan(2);
PdfPCell cell1 = new PdfPCell(new Phrase(company.getUsername()+","+company.getMerchantNum(),font));
// Paragraph pp=new Paragraph("מספר קבלה");
// BaseFont unicode = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H , BaseFont.EMBEDDED);
// Font fontHebrew = new Font(unicode, 12, Font.NORMAL);
// pp.setAlignment(Paragraph.ALIGN_CENTER);
// pp.setFont(fontHebrew);
// table.addCell(pp);
table.addCell("מספר קבלה");
// table.addCell(new String(("מספר קבלה").getBytes(), "UTF-16"));
table.addCell("0");//לשנות מספר חשבונית
table.addCell("שם הלקוח");
// String data = "\u092a\u093e\u0932\u094d\u092a\u093e\u0915\u093e \u092c\u0928\u094d\u0926\u0940\u0939\u0930\u0942 \u0915\u093e\u0930\u093e\u0917\u093e\u0930\u092d\u093f\u0924\u094d\u0930\u0948 \u0905\u0938\u0941\u0930\u0915";
// byte[] bute = null;
// String asd = null;
// bute = data.getBytes("מייל");
// try {
// asd= new String(bute, "UTF-8");
//
// System.out.println(asd);
// } catch (UnsupportedEncodingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// table.addCell(asd);
table.addCell(transaction.getName());
table.addCell("mail");
table.addCell(transaction.getEmail());
// table.addCell("טלפון");
table.addCell("phone");
table.addCell(transaction.getPhone());
// table.addCell("כרטיס שמספרו");
table.addCell("Numbered card");
table.addCell((transaction.getCreditNum().substring(transaction.getCreditNum().length()-4)));
// table.addCell("חברת האשראי");
table.addCell("Credit card company");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = null ;
switch (transaction.getImgCredit()) {
case 1:bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.isracard);break;
case 2:bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.visa);break;
case 3:bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.diners);break;
case 4:bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.amex);break;
case 6:bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.leumicard);break;
default:
break;
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.setAlignment(Image.MIDDLE);
table.addCell(myImg);
// table.addCell("סוג עסקה");
table.addCell("Type of transaction");
switch (Integer.parseInt(transaction.getTypeTrans())) {
case 01: table.addCell(" Required deal");break;
case 51: table.addCell("Right deal");break;
// case 01: table.addCell(" עסקת חובה");break;
// case 51: table.addCell("עסקת זכות");break;
default:
break;
}
// table.addCell("סכום עסקה");
table.addCell("Transaction amount");
table.addCell(transaction.getPrice().toString());
// table.addCell("סוג תשלום");
table.addCell("Type of Payment");
switch (Integer.parseInt(transaction.getTypeCredit())) {
// case 1:table.addCell("רגיל");break;
// case 6:table.addCell("קרדיט");break;
// case 8:table.addCell("תשלומים");break;
case 1:table.addCell("Standard");break;
case 6:table.addCell("Credit");break;
case 8:table.addCell("Payments");break;
default:
break;
}
// table.addCell("מספר תשלומים");
table.addCell("Number of payments");
table.addCell(transaction.getNumPayments()+"");
// table.addCell("תשלום ראשון");
table.addCell("Downpayment");
table.addCell(transaction.getFirstPay()+"");
// table.addCell("חתימה");
table.addCell("Signature");
table.addCell("Signature ccc");
doc.add(table);
//set footer
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
}
finally
{
doc.close();
}
}
פורסם במקור בפורום CODE613 ב25/02/2014 11:16 (+02:00)