java - Add page title between PdfPTables in iText -
i have number of pdfptable
s following each other this:
is possible add title on of page(not first page)? believe cant use pdfpageeventhelper
because table first on each page needs moved down(to not overlap title).
any ideas or tips how can solved? cant figure out how know if there has been new page or not each of tables.
public class tabledemo { /** resulting pdf file. */ public static final string result = "first_table.pdf"; /** * main method. * @param args no arguments needed * @throws documentexception * @throws ioexception */ public static void main(string[] args) throws ioexception, documentexception { new tabledemo().createpdf(result); } /** * creates pdf tables * @param filename name of pdf file created. * @throws documentexception * @throws ioexception */ public void createpdf(string filename) throws ioexception, documentexception { document document = new document(); pdfwriter.getinstance(document, new fileoutputstream(filename)); document.open(); document.add(addtitle()); for(int i=0; i<10; i++) document.add(createtable()); document.close(); } /** * creates our table * @return our table */ public static pdfptable createtable() { pdfptable table = new pdfptable(4); int rows = (int)(math.random()*30+1); for(int row=0; row<rows; row++){ for(int cell=0; cell<4; cell++){ table.addcell("row "+row+"; cell "+cell); } } table.setkeeptogether(true); table.setspacingafter(30); return table; } public static paragraph addtitle(){ font fontbold = fontfactory.getfont("times-roman", 40, font.bold); paragraph p = new paragraph("title on each page", fontbold); p.setspacingafter(20); p.setalignment(1); // center return p; } }
Comments
Post a Comment