itextsharp - Unable to left-align nested tables inside a cell -



itextsharp - Unable to left-align nested tables inside a cell -

the next code produce table , nested table. however, nested table aligned in middle. have no clue how accomplish horizontal alignment properly.

the next method looping through list. when it's simple question, add together textfield. if it's question containing multiple answers, inject nested table checkboxes , values.

private pdfptable createquestiontable(rlquestionrecordlist questions) { pdfpcell cell; pdfptable table = new pdfptable(2); //table.setwidths(new int[]{ 50, 50 }); table.widthpercentage = 100; table.spacingbefore = 20; table.spacingafter = 20; table.defaultcell.horizontalalignment = element.align_left; foreach (rcquestionrecord q in questions) { //add question table cell = new pdfpcell(new phrase(q.ssstquestion.ssname, _normal)); cell.border = rectangle.no_border; cell.padding = 5.0f; table.addcell(cell); //add reply table. //add generate time don;t know table be, //hence textfields generated after pdf has been generated.. if (q.ssstquestion.sslistofanswers.length > 0) { // have radiobuttons, add together table within cell cell = new pdfpcell(); cell.border = rectangle.no_border; cell.padding = 5.0f; //we cannot align table left in cell weird reason... cell.horizontalalignment = element.align_left; cell.addelement(createcheckboxtable(q)); table.addcell(cell); } else { // have simple textfield, add together cell cell = new pdfpcell(); cell.border = rectangle.no_border; cell.padding = 5.0f; cell.horizontalalignment = element.align_left; //simple textfield cell.cellevent = new oomtextfield(string.format("question_{0}", q.ssstquestion.ssquestionid), q.ssstquestion.sslength, q.ssstquestion.ssvalue, bf); table.addcell(cell); } } homecoming table; }

this nested table want insert cell above.

/// <summary> /// /// </summary> /// <param name="question"></param> /// <returns></returns> private pdfptable createcheckboxtable(rcquestionrecord question) { pdfpcell cell; int numcells = question.ssstquestion.sslistofanswers.length; pdfptable table = new pdfptable(numcells); float[] widths = new float[numcells]; int currentcolumn = 0; //table.setwidths(new int[]{ 50, 50 }); foreach (rcanswerrecord in question.ssstquestion.sslistofanswers) { //checkbox cell = new pdfpcell(new phrase(a.ssstanswer.sslabel, _normal)); cell.border = rectangle.no_border; cell.padding = 0.0f; cell.paddingleft = 20.0f; cell.horizontalalignment = element.align_left; cell.verticalalignment = element.align_center; cell.cellevent = new oomcheckbox(string.format("question_{0}", question.ssstquestion.ssquestionid), a.ssstanswer.ssisselected, a.ssstanswer.sslabel, bf); //checkbox table.addcell(cell); widths[currentcolumn++] = 20.0f + bf.getwidthpoint(a.ssstanswer.sslabel, 11); } table.settotalwidth(widths); table.lockedwidth = true; table.spacingbefore = 0; homecoming table; }

what missing align nested tables totally left within cell?

please take @ pdf document named nested_tables_aligned.pdf:

the outer table in illustration has 3 columns , 1 row. each cell in outer table contains inner table. first inner table left aligned, sec 1 center aligned, 3rd 1 right aligned.

this pdf created java illustration named nestedtablesaligned:

public void createpdf(string dest) throws ioexception, documentexception { document document = new document(pagesize.a4.rotate()); pdfwriter.getinstance(document, new fileoutputstream(dest)); document.open(); float[] columnwidths = {200f, 200f, 200f}; pdfptable table = new pdfptable(columnwidths); table.settotalwidth(600f); table.setlockedwidth(true); buildnestedtables(table); document.add(table); document.close(); } private void buildnestedtables(pdfptable outertable) { pdfptable innertable1 = new pdfptable(1); innertable1.settotalwidth(100f); innertable1.setlockedwidth(true); innertable1.sethorizontalalignment(element.align_left); innertable1.addcell("cell 1"); innertable1.addcell("cell 2"); outertable.addcell(innertable1); pdfptable innertable2 = new pdfptable(2); innertable2.settotalwidth(100f); innertable2.setlockedwidth(true); innertable2.sethorizontalalignment(element.align_center); innertable2.addcell("cell 3"); innertable2.addcell("cell 4"); outertable.addcell(innertable2); pdfptable innertable3 = new pdfptable(2); innertable3.settotalwidth(100f); innertable3.setlockedwidth(true); innertable3.sethorizontalalignment(element.align_right); innertable3.addcell("cell 5"); innertable3.addcell("cell 6"); outertable.addcell(innertable3);

}

as can see, define alignment of table @ level of table, not @ level of cell. sample principle applies itextsharp. in c# example, define aligned pdfpcell instead of pdfptable. alter , problem solved.

itextsharp itext

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -