java - How to render Paragraph in vertical cell in itext7? -
i want build table headers in itext7. :
here code :
package utils; import datamodels.ishvaxtidata; import com.itextpdf.io.font.fontconstants; import com.itextpdf.kernel.color.color; import com.itextpdf.kernel.events.event; import com.itextpdf.kernel.events.ieventhandler; import com.itextpdf.kernel.events.pdfdocumentevent; import com.itextpdf.kernel.font.pdffont; import com.itextpdf.kernel.font.pdffontfactory; import com.itextpdf.kernel.geom.pagesize; import com.itextpdf.kernel.geom.rectangle; import com.itextpdf.kernel.pdf.pdfdocument; import com.itextpdf.kernel.pdf.pdfname; import com.itextpdf.kernel.pdf.pdfnumber; import com.itextpdf.kernel.pdf.pdfwriter; import com.itextpdf.kernel.pdf.canvas.pdfcanvas; import com.itextpdf.kernel.pdf.canvas.pdfcanvasconstants; import com.itextpdf.kernel.pdf.xobject.pdfformxobject; import com.itextpdf.layout.canvas; import com.itextpdf.layout.document; import com.itextpdf.layout.style; import com.itextpdf.layout.border.border; import com.itextpdf.layout.element.*; import com.itextpdf.layout.layout.layoutarea; import com.itextpdf.layout.layout.layoutcontext; import com.itextpdf.layout.layout.layoutresult; import com.itextpdf.layout.property.*; import com.itextpdf.layout.renderer.cellrenderer; import com.itextpdf.layout.renderer.drawcontext; import com.itextpdf.layout.renderer.irenderer; import com.itextpdf.layout.renderer.tablerenderer; import com.itextpdf.signatures.pdfsignatureappearance; import java.io.file; import java.io.ioexception; import java.util.list; public class test { private static string file = "c:/codes/java/firstpdf.pdf"; public static int header_font_size = 8; public static int sub_header_font_size = 8; public static void main(string[] args) throws exception{ pishvaxtitopdf(null,file,"",2,2); //test test2 = new test(); //test2.manipulatepdf(file); } public static void pishvaxtitopdf(list<ishvaxtidata> list, string dest, string name , int year, int month) throws exception{ pdfdocument pdfdocument = new pdfdocument(new pdfwriter(dest)); document document = new document(pdfdocument,pagesize.a4.rotate()); pdffont pdffont = pdffontfactory.createfont("c:\\windows\\fonts\\arial.ttf", "identity-h", true); int g = 2; table table = new table( new float[]{ g,g,g, g,g,g,g,g, g,g,g,g,g, g,g,g,g,g, g,g,g,g,g, g,g,g,g,g, g,g,g,g,g, g,g,g,g,g, g,g,g,g } ); //table.setkeeptogether(true); //table.setheight(700); table.setwidthpercent(100); cell cell; //sira nomresi; cell = new cell(2,1); cell.add( new paragraph(constants.pishvaxti.n).setrotationangle(1.5707963268) ); cell.setfontsize(header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.middle); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); // soyadi adi atasinin adi cell = new cell(2,1); cell.add( new paragraph(constants.pishvaxti.adsoyad).setfont(pdffont) ); cell.setfontsize(header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.middle); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //ixtisas cell = new cell(2,1); cell.add( new paragraph(constants.pishvaxti.vezifesi).setfont(pdffont) ); cell.setfontsize(8); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.middle); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //ayin gunleri cell = new cell(1,30); cell.add( new paragraph(constants.pishvaxti.ayingunleri).setfont(pdffont) ); cell.setfontsize(header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.middle); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //faktikiishecixma cell = new cell(2,1); paragraph paragraph = new paragraph(constants.pishvaxti.faktikiishecixma) .setfont(pdffont).setrotationangle(1.5707963268) //.setverticalalignment(verticalalignment.bottom) ; cell.add( paragraph ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); cell.setmargins(0,0,0,0).setpaddings(0,0,0,0); table.addheadercell(cell); //ishecixmagunleri cell = new cell(1,4); cell.add( new paragraph(constants.pishvaxti.ishecixmamagunleri).setfont(pdffont) ); cell.setfontsize(header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.middle); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //bayramveistirahet cell = new cell(2,1); cell.add( new paragraph(constants.pishvaxti.bayramveistirahet).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.middle); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //ishlenmishsaatlar cell = new cell(1,3); cell.add( new paragraph(constants.pishvaxti.ishlenmishsaatlar).setfont(pdffont) ); cell.setfontsize(header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.middle); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //ayingunleri for(int = 1; <= 30 ; ++i){ cell = new cell(1,1); cell.add( new paragraph( string.valueof(i + "") ).setfont(pdffont) ); cell.setfontsize(header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); } //xestelik cell = new cell(1,1); cell.add( new paragraph(constants.pishvaxti.xestelik).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //rehberliyinicazesi cell = new cell(1,1); cell.add( new paragraph(constants.pishvaxti.rehberinicazesi ).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //ozhesabina cell = new cell(1,1); cell.add( new paragraph(constants.pishvaxti.ozhesabina).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //mezuniyyet cell = new cell(1,1); cell.add( new paragraph(constants.pishvaxti.mezuniyyet).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //cemi cell = new cell(1,1); cell.add( new paragraph(constants.pishvaxti.cemi).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //ishvaxtinaelave cell = new cell(1,1); cell.add( new paragraph(constants.pishvaxti.ishvaxtinaelave).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //1.15 cell = new cell(1,1); cell.add( new paragraph(constants.pishvaxti.birondabesh).setfont(pdffont).setrotationangle(1.5707963268) ); cell.setfontsize(sub_header_font_size); cell.settextalignment(textalignment.center); cell.setverticalalignment(verticalalignment.bottom); cell.sethorizontalalignment(horizontalalignment.center); table.addheadercell(cell); //table.setmarginleft(0); document.setleftmargin(0); table.getheader().setheight(100); //table.getheader().setwidth(100); system.out.println( table.getheader().getwidth() ); //system.out.println( document.getwidth() ); document.add(table); document.close(); } }
paragraphs vertical have multiple lines. need single line paragraphs in first image. other problem there more empty space in vertical cell need. tried set padding , margin of cell , paragraph zero. have no effect
Comments
Post a Comment