java - Special alignment using itext -


how can alignment on itext :

from lines :

itext use java, itext write pdf docs java 

can :

                        itext                         use java, itext write pdf docs                         java 

the second line centered.

what want not easy obtained itext can possible way it. can create 1 row 3 column table , putting text in middle column align_left. problem solution column's width in itext must set manually, have compute @ run time needed width of middle cell obtain desired output.

here example:

string[] rows = {"line 1", "line 222222222222222222", "line 3", "line 4 qwertopasdfvbnm"};  document document = new document(); pdfwriter.getinstance(document, new fileoutputstream("c:/simplepdf.pdf")); document.open();  document.newpage();  // creating pdfptable 3 cell [empty][your test][empty] pdfptable table = new pdfptable(3); pdfpcell fake = new pdfpcell();  fake.setborder(rectangle.no_border); // hiding border table.addcell(fake);  // creating middle cell pdfpcell c = new pdfpcell(); c.sethorizontalalignment(element.align_left); c.setborder(rectangle.no_border);  // adding strings middle cell (string string : rows) {     c.addelement(new paragraph(string)); }  table.addcell(c);  table.addcell(fake);  // setting manually column widths // depending on string length added before, should // max length string , compute width middle cell,  // others 2 (100% - middle_cell_width)/2 float[] columnwidths = {30f, 40f, 30f}; table.setwidths(columnwidths);  document.add(table); document.close(); 

here how displayed:

output screenshot


Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

tsql - Pivot with Temp Table (definition for column must include data type) -- SQL Server 2008 -