我正在我的应用程序中生成发票(PDF)。生成PDF文件后,我需要推送通知。用户单击推送通知时,应通过默认应用程序打开PDF文件。
try
{
Date date2 = new Date();
DateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
String time = DateUtils.formatDateTime(thisActivity, date2.getTime(), DateUtils.FORMAT_SHOW_TIME);
String Date = sdf.format(date2);
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(Environment.getExternalStorageDirectory() +"/" + Invoice + "invoice.pdf"));
document.open();
document.getPageSize();
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell();
cell.addElement(new Paragraph("test"));
cell.addElement(new Paragraph("test"));
cell.addElement(new Paragraph("GSTIN : "+ GST));
cell.addElement(new Paragraph(test));
cell.addElement(new Paragraph(Email));
cell.setPadding(5);
table.addCell(cell);
PdfPTable table1 = new PdfPTable(2);
PdfPTable table2 = new PdfPTable(5);
PdfPCell cell1 = new PdfPCell();
cell1.addElement(new Paragraph(ShopName));
cell1.addElement(new Paragraph(ShopAddress));
cell1.addElement(new Paragraph(LandMark));
PdfPCell cell2 = new PdfPCell();
cell2.addElement(new Paragraph("Billing_Invoice Date : " + Date));
cell2.addElement(new Paragraph("Billing_Invoice No : "+ Invoice));
table1.addCell(cell1);
table1.addCell(cell2);
PdfPCell serilno = new PdfPCell(new Phrase("S.NO"));
PdfPCell description = new PdfPCell(new Phrase("Description"));
PdfPCell qty = new PdfPCell(new Phrase("Qty"));
PdfPCell price = new PdfPCell(new Phrase("Price"));
PdfPCell amount = new PdfPCell(new Phrase("Amount"));
table2.addCell(serilno);
table2.addCell(description);
table2.addCell(qty);
table2.addCell(price);
table2.addCell(amount);
int sNO = 0, qTY = 0, TotalCharges = 0, Price = 0;
String ProductType, Type, Veriety;
for (int i = 0; i < DeliverOrderlist.size(); i++){
sNO = i + 1;
ProductType = DeliverOrderlist.get(i).getProduct();
Type = DeliverOrderlist.get(i).getType();
serilno.addElement(new Paragraph(String.valueOf(sNO)));
Veriety = DeliverOrderlist.get(i).getVariety();
qTY = DeliverOrderlist.get(i).getUnitCount();
qty.addElement(new Paragraph(String.valueOf(qTY)));
description.addElement(new Paragraph(ProductType + " " + Type + " " + Veriety));
Price = Integer.parseInt(Billing_InvoiceAdapter.dataList.get(i).getEditTextValue());
Price = enteredNumber[i];
price.addElement(new Paragraph(String.valueOf(Price)));
int result = qTY * Price;
amount.addElement(new Paragraph(String.valueOf(result)));
TotalCharges += result;
}
table2.addCell(serilno);
table2.addCell(description);
table2.addCell(qty);
table2.addCell(price);
table2.addCell(amount);
PdfPTable table3 = new PdfPTable(2);
PdfPCell TotalValue = new PdfPCell(new Phrase("Total Value"));
PdfPCell TotalCharge = new PdfPCell(new Phrase("Rs: " + String.valueOf(TotalCharges)));
TotalCharge.setPaddingLeft(50);
TotalValue.setPaddingTop(5);
TotalValue.setPaddingBottom(5);
TotalCharge.setPaddingTop(5);
TotalCharge.setPaddingBottom(5);
table3.addCell(TotalValue);
table3.addCell(TotalCharge);
String PricenWrods = EnglishNumberToWords.convert(TotalCharges);
PdfPTable table4 = new PdfPTable(1);
PdfPCell AmtnWords = new PdfPCell(new Phrase("Amount in words : " + PricenWrods + " " + "only"));
AmtnWords.setPaddingTop(5);
AmtnWords.setPaddingBottom(5);
table4.addCell(AmtnWords);
document.add(table);
document.add(table1);
document.add(table2);
document.add(table3);
document.add(table4);
Toast.makeText(thisActivity, "Invoice Generated!!", Toast.LENGTH_SHORT).show();
document.close();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (DocumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
这是我生成PDF文件(发票)的方式。谁能帮我这个?预先感谢。