引用我使用ItextPdf生成PDF文件,但我在這條線canvas.addImage(background, width, 0,0, height, 20, 430);
即型號java.awt.geom.AffineTransform
無法解析得到一個例外。它是從所需的.class
文件間接引用的。在這一行我試圖設置背景圖像。請幫我解決這個例外。無法解析java.awt.geom.AffineTransform類型。它是間接需要的.class文件
public void createPDF() throws NumberFormatException, ParseException
{
list1.add("I-Tax Number : ");
list1.add("Category : ");
list1.add("Service : ");
list1.add("Number : ");
list1.add("Amount : ");
list1.add("Status : ");
list2.add(iTaxNumber);
list2.add("Bill Payment");
list2.add("Idea Postapid");
list2.add("9644212111");
list2.add("100");
list2.add("SUCCESS");
Font trfont = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLDITALIC,
new BaseColor(130, 130, 140));
Font otherfont = new Font(FontFamily.TIMES_ROMAN, 12, Font.NORMAL,
new BaseColor(160, 160, 160));
Font datefont = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD,
new BaseColor(130, 130, 140));
Font thanksFont = new Font(FontFamily.TIMES_ROMAN, 14, Font.BOLDITALIC,
new BaseColor(130, 130, 140));
Document doc = new Document(new Rectangle(792, 612));
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, "demo98989.pdf");
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter docPdfWriter = PdfWriter.getInstance(doc, fOut);
Paragraph fromTotoDate = new Paragraph("Date : 25-oct-2015", datefont);
fromTotoDate.setAlignment(Element.ALIGN_RIGHT);
fromTotoDate.setIndentationRight(5);
doc.addAuthor("betterThanZero");
doc.addCreationDate();
doc.addProducer();
doc.addCreator("www.xyz.com");
doc.setPageSize(PageSize.A4);
doc.open();
PdfPTable table = setTable(list1, list2);
Paragraph trId = new Paragraph("Transaction Id : 889879899", trfont);
trId.setAlignment(Element.ALIGN_RIGHT);
trId.setIndentationRight(65);
Paragraph p = new Paragraph("\n\n\n\n");
Paragraph nextline = new Paragraph("\n");// for blank line
doc.add(fromTotoDate);
doc.add(p);
doc.add(trId);
int list1size = list1.size();
String size = String.valueOf(list1size);
Image trDetails_Icon;
Bitmap bmp = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.trreceipt);
ByteArrayOutputStream streamTrReceipt = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, streamTrReceipt);
trDetails_Icon = Image.getInstance(streamTrReceipt.toByteArray());
trDetails_Icon.scaleAbsolute(445f, 238f);
trDetails_Icon.setAbsolutePosition(76, 516);
doc.add(trDetails_Icon);
doc.add(nextline);
doc.add(table);
Paragraph thanktouMessage = new Paragraph("Thanks for Being with Us ! ", thanksFont);
thanktouMessage.setAlignment(Element.ALIGN_CENTER);
doc.add(nextline);
doc.add(thanktouMessage);
Font contFont = new Font(FontFamily.TIMES_ROMAN, 10, Font.NORMAL,
new BaseColor(130, 130, 140));
doc.add(nextline);
Paragraph cont = new Paragraph("For more info contact us", contFont);
cont.setAlignment(Element.ALIGN_RIGHT);
cont.setIndentationRight(20);
doc.add(cont);
System.out.println("list2.get(1) = "+list2.get(1));
float width;
float height;
Image background;
Bitmap bmp1 = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.trans);
ByteArrayOutputStream streamTrReceipt1 = new ByteArrayOutputStream();
bmp1.compress(Bitmap.CompressFormat.PNG, 100, streamTrReceipt1);
System.out.println("list2.get(1) = "+list2.get(1)+"ELSE");
width = PageSize.A4.getWidth()-40;
height = (PageSize.A4.getHeight()/2)-25;
background = Image.getInstance(streamTrReceipt1.toByteArray());
PdfContentByte canvas = docPdfWriter.getDirectContentUnder();
canvas.addImage(background, width, 0,0, height, 20, 430);
Toast.makeText(getApplicationContext(), "Created...", Toast.LENGTH_LONG).show();
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
}
finally
{
doc.close();
}
}
我很好奇,這些類是「禁止的」還是僅僅出現在Google選擇在Android中使用的Java API子集中?我認爲這是後者,但我可能是錯的。 –
Google選擇在Android中使用的Java API子集中不存在。 Dalvik虛擬機不知道它們。原因:不同的映像模型和不同的文件處理方式,特別是在Google App Engine環境中(雲中的*文件系統*與磁盤上的文件系統不同)。 –