java - First table font colour getting dark using itext in pdf -
i developing android application requirement create tables in pdf, using itextpdf5.3.4
.
i having problem related table in pdf. creating 25 records in 1 table @ absolute position.if having more 25 records means creating 1 more table in new page. if having 2 tables, text in first table getting dark font.
below pasting code:
document document = new document(); seek { file file = new file(environment.getexternalstoragedirectory().getabsolutepath() + "/report.pdf"); initializefonts(); font hedder_font= new font(bfbold, 8); font content_font = new font(bf, 8); font color_font = new font(bf, 8); color_font.setcolor(new basecolor(0,172,237)); pdfwriter docwriter= pdfwriter.getinstance(document, new fileoutputstream(file)); docwriter.setrgbtransparencyblending(true); basereportbuilder event = new basereportbuilder(); docwriter.setpageevent(event); document.open(); pdfcontentbyte cb = docwriter.getdirectcontent(); if (list.size() > 0) { createheadings(cb,25,620,"details",10,bfbold); } //list products sold client float[] columnwidths = {0.5f,3f, 1f, 1f,1f}; //create pdf table given widths pdfptable table = new pdfptable(columnwidths); // set table width percentage of page width table.settotalwidth(500f); pdfpcell cell = new pdfpcell(new phrase("sr",hedder_font)); cell.sethorizontalalignment(element.align_right); table.addcell(cell); cell = new pdfpcell(new phrase("item ",hedder_font)); cell.sethorizontalalignment(element.align_left); table.addcell(cell); cell = new pdfpcell(new phrase("date",hedder_font)); cell.sethorizontalalignment(element.align_left); table.addcell(cell); cell = new pdfpcell(new phrase("id",hedder_font)); cell.sethorizontalalignment(element.align_right); table.addcell(cell); cell = new pdfpcell(new phrase("amount",hedder_font)); cell.sethorizontalalignment(element.align_right); table.addcell(cell); table.setheaderrows(1); if (list.size() > 25) { int value =630; (int = 0; < 25; i++) { system.out.println("i" + i); value = value - 15; string date = list.get(i).getcreated_on(); table.addcell(new pdfpcell(new phrase(string.valueof(i+1),content_font))); table.addcell(new pdfpcell(new phrase(list.get(i).getitem(),content_font))); table.addcell(new pdfpcell(new phrase(date,content_font))); table.addcell(new pdfpcell(new phrase(list.get(i).getcategory_name(), content_font))); table.addcell(new pdfpcell(new phrase(list.get(i).getamount(), content_font))); table.writeselectedrows(0, -1, document.leftmargin(),610, docwriter.getdirectcontent()); } document.newpage(); //create pdf table given widths pdfptable table1 = new pdfptable(columnwidths); // set table width percentage of page width table1.setspacingafter(250f); table1.settotalwidth(500f); (int = 25; < list.size(); i++) { string date = list.get(i).getcreated_on(); table1.addcell(new pdfpcell(new phrase(string.valueof(i+1),content_font))); table1.addcell(new pdfpcell(new phrase(list.get(i).getitem(), content_font))); table1.addcell(new pdfpcell(new phrase(date,content_font))); table1.addcell(new pdfpcell(new phrase(list.get(i).getitemid(), content_font))); table1.addcell(new pdfpcell(new phrase(list.get(i).getamount(), content_font))); } //absolute location print pdf table from if (list.size() > 0) { table1.addcell(new pdfpcell(new phrase("total",content_font))); table1.addcell(new pdfpcell(new phrase("",content_font))); table1.addcell(new pdfpcell(new phrase("",content_font))); table1.addcell(new pdfpcell(new phrase("",content_font))); table1.addcell(new pdfpcell(new phrase(""+""+total,hedder_font))); } document.add(table1); } else { (int = 0; < list.size(); i++) { system.out.println("i"+i); string date = list.get(i).getcreated_on(); table.addcell(new pdfpcell(new phrase(string.valueof(i+1),content_font))); table.addcell(new pdfpcell(new phrase(list.get(i).getitem(),content_font))); table.addcell(new pdfpcell(new phrase(date,content_font))); table.addcell(new pdfpcell(new phrase(list.get(i).getitemid(), content_font))); table.addcell(new pdfpcell(new phrase(list.get(i).getamount(), content_font))); } if (list.size() > 0) { table.addcell(new pdfpcell(new phrase("total",content_font))); table.addcell(new pdfpcell(new phrase("",content_font))); table.addcell(new pdfpcell(new phrase("",content_font))); table.addcell(new pdfpcell(new phrase("",content_font))); table.addcell(new pdfpcell(new phrase(""+""+total,hedder_font)));} table.writeselectedrows(0, -1, document.leftmargin(),610, docwriter.getdirectcontent()); } system.out.println("docwriter.getverticalposition(true)" + docwriter.getverticalposition(true)); if (docwriter.getverticalposition(true) < 100) { document.newpage(); } createheadings(cb,30,100,"number of items : " +list.size(),12,bfbold); createheadings(cb,495,100,": " +list.size(),11,bfbold); createheadings(cb,350,75,"total :",11,bfbold); createheadings(cb,495,75,": " +total,12,bfbold); document.close(); } } catch(exception e){ e.printstacktrace(); }
private void initializefonts() { seek { bfbold = basefont.createfont(basefont.helvetica_bold, basefont.cp1252, basefont.not_embedded); bf =basefont.createfont(basefont.helvetica, basefont.cp1252, basefont.not_embedded); } grab (documentexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } }
java android itext
No comments:
Post a Comment