itext - How to create dynamic pdf cells in C# mvc -


i have view containing table has more 30 columns changing month want print pdf.but need create pdf cell dynamically.ie if select month august pdf have 30 columns if select february pdf have 28 columns how can please me.below code. [![table print pdf][1]][1]

document pdfdoc = new document(pagesize.a4, 40f, 40f, 30f, 30f); //     document pdf = new document(pagesize.a4,) pdfwriter.getinstance(pdfdoc, response.outputstream); pdfdoc.open();  pdfptable tablebody = new pdfptable(pdfcell); tablebody.totalwidth = 500f;  pdfpcell cell0 = new pdfpcell(new phrase(" georoof \n\n monthly field visit report", new font(font.fontfamily.helvetica, 12f, font.bold))); cell0.colspan = 7; cell0.horizontalalignment = 1; //0=left, 1=centre, 2=right cell0.paddingbottom = 6f; cell0.paddingtop = 6f; tablebody.addcell(cell0);  pdfpcell cell1 = new pdfpcell(new phrase("dealer", new font(font.fontfamily.helvetica, 10f, font.bold))); cell1.colspan = 1; cell1.horizontalalignment = 1; //0=left, 1=centre, 2=right cell1.paddingbottom = 6f; cell1.paddingtop = 6f; tablebody.addcell(cell1);  pdfpcell cell2 = new pdfpcell(new phrase("executive", new font(font.fontfamily.helvetica, 10f, font.bold))); cell2.colspan = 1; cell2.horizontalalignment = 1; //0=left, 1=centre, 2=right cell2.paddingbottom = 6f; cell2.paddingtop = 6f; tablebody.addcell(cell2);  pdfpcell cell3 = new pdfpcell(new phrase("days", new font(font.fontfamily.helvetica, 10f, font.bold))); cell3.colspan = 1; cell3.horizontalalignment = 1; //0=left, 1=centre, 2=right cell3.paddingbottom = 6f; cell3.paddingtop = 6f; tablebody.addcell(cell3);  (int = 4, j = 4; <= daysinmonth; i++) {     string cells = i.tostring();     pdfpcell cell = new pdfpcell(new phrase(cells, new font(font.fontfamily.helvetica, 10f, font.bold)));      cell3.horizontalalignment = 1; //0=left, 1=centre, 2=right     cell3.paddingbottom = 6f;     cell3.paddingtop = 6f;     tablebody.addcell(cell3);     j++; } 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -