c# - How to append a table in PDF using iTextsharp without knowing the exact number of pages the table will produce -


i'm using itextsharp create pdf , i'm creating multiple tables run inline in code. won't know how long table going when fill values collection. , don't want 1 table run or through next. have far, if table runs next page, overlaps table placed in next line of code page break -newpage()-

// page 1 searches              doc.newpage();              cb.begintext();             centertext(cb, "headertext searches", 300, 760, _fontbold, 18);             cb.endtext();              pdfptable tablesearches = new pdfptable(4);             pdfpcell cellsearches = new pdfpcell();              cellsearches.backgroundcolor = basecolor.white;              cellsearches.phrase = new phrase("company");             tablesearches.addcell(celllkq);             cellsearches.phrase = new phrase("contact");             tablesearches.addcell(celllkq);             cellsearches.phrase = new phrase("phone number");             tablesearches.addcell(celllkq);             cellsearches.phrase = new phrase("amount");             tablesearches.addcell(celllkq);              //loop through records in facilities collection , add row             foreach (var m in facilities)             {                 cellsearches.backgroundcolor = basecolor.light_gray;                  cellsearches.phrase = new phrase(m.facility);                 tablesearches.addcell(cellsearches);                  cellsearches.phrase = new phrase(m.facilitycontact);                 tablesearches.addcell(cellsearches);                  cellsearches.phrase = new phrase(m.phone);                 tablesearches.addcell(cellsearches);                  cellsearches.phrase = new phrase(m.salvagequote.tostring());                 tablesearches.addcell(cellsearches);             }              doc.add(tablesearches);              //page 2? searches              doc.newpage();              cb.begintext();             centertext(cb, "headertext searches", 300, 760, _fontbold, 18);             cb.endtext();              pdfptable tableam = new pdfptable(4);             pdfpcell cellam = new pdfpcell();              cellam.backgroundcolor = basecolor.white;              cellam.phrase = new phrase("company");             tableam.addcell(cellam);             cellam.phrase = new phrase("contact");             tableam.addcell(cellam);             cellam.phrase = new phrase("phone number");             tableam.addcell(cellam);             cellam.phrase = new phrase("amount");             tableam.addcell(cellam);              //loop through records , add row             foreach (var m in amfacilities)             {                 cellam.backgroundcolor = basecolor.cyan;                 cellam.phrase = new phrase(m.facility);                 tableam.addcell(cellam);                  cellam.phrase = new phrase(m.facilitycontact);                 tableam.addcell(cellam);                  cellam.phrase = new phrase(m.phone);                 tableam.addcell(cellam);                  celllkq.phrase = new phrase(m.salvagequote.tostring());                 tableam.addcell(cellam);             }              doc.add(tableam);              //page 3? table               doc.newpage();            // code next table 

just removed contentbyte , added new paragraph document. quite solved needed achive: table title header, new table starting on new page.

        doc.open();          doc.add(new paragraph(new chunk("header searches" + chunk.newline + chunk.newline, fb)));          pdfptable tablesearches = new pdfptable(3);         pdfpcell cellsearches = new pdfpcell();          cellsearches.backgroundcolor = basecolor.white;          cellsearches.phrase = new phrase("facility id");         tablesearches.addcell(cellsearches);         cellsearches.phrase = new phrase("facility");         tablesearches.addcell(cellsearches);         cellsearches.phrase = new phrase("phone number");         tablesearches.addcell(cellsearches);          //loop through records in facilities collection , add row         foreach (var m in facilitylist)         {             cellsearches.backgroundcolor = basecolor.light_gray;              cellsearches.phrase = new phrase(m.id.tostring());             tablesearches.addcell(cellsearches);              cellsearches.phrase = new phrase(m.facility);             tablesearches.addcell(cellsearches);              cellsearches.phrase = new phrase(m.phone);             tablesearches.addcell(cellsearches);         }          doc.add(tablesearches);          //page 2? searches          doc.newpage();          doc.add(new paragraph(new chunk("header searches" + chunk.newline + chunk.newline, fb)));          pdfptable tableam = new pdfptable(3);         pdfpcell cellam = new pdfpcell();          cellam.backgroundcolor = basecolor.white;          cellam.phrase = new phrase("facility id");         tableam.addcell(cellam);         cellam.phrase = new phrase("facility");         tableam.addcell(cellam);         cellam.phrase = new phrase("phone number");         tableam.addcell(cellam);          //loop through records , add row         foreach (var m in facilitylist)         {             cellam.backgroundcolor = basecolor.cyan;             cellam.phrase = new phrase(m.id.tostring());             tableam.addcell(cellam);              cellam.phrase = new phrase(m.facility);             tableam.addcell(cellam);              cellam.phrase = new phrase(m.phone);             tableam.addcell(cellam);         }          doc.add(tableam);          doc.close(); 

enter image description here


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -