java - iText setRowspan not working for tables in headers? -


exactly same code used create pdfptable main body of document , document's page header. table rendered in main body doesn't seem take account setrowspan values in header.

below paste screenshot of produced pdf and, after that, minimal standalone program used generate pdf.

pdf output

enter image description here

code

import java.io.*; import com.itextpdf.text.*; import com.itextpdf.text.pdf.*;  class headerandfooter extends pdfpageeventhelper{      private pdfptable header;      public headerandfooter() throws exception {         header = foomain.createtable();         header.settotalwidth(530);     }      @override     public void onendpage(pdfwriter writer, document document) {         pdfcontentbyte cb = writer.getdirectcontent();         float x   = document.leftmargin();         float hei = header.gettotalheight();         float y   = document.top()+hei;         header.writeselectedrows(0, -1, x , y, cb);     } }  public class foomain {      public static void main(string[] args) throws exception {         document doc = new document(pagesize.a4, 30, 30, 150, 40);         pdfwriter writer = pdfwriter.getinstance(doc, new fileoutputstream("./brokentableinheader.pdf"));         writer.setpageevent(new headerandfooter());         doc.open();         doc.add(createtable());         doc.close();     }      public static pdfptable createtable() throws exception {         pdfptable table = new pdfptable(2);         pdfpcell cell = new pdfpcell(new phrase("cell spanning 2 rows"));          cell.setrowspan(2);         table.addcell(cell);         table.addcell( new phrase ("a"));         table.addcell( new phrase ("b"));         return table;     } } 

found answer in this question (use columntext::go instead of pdfptable::writeselectedrows)

here's excerpt working code:

columntext column = new columntext(writer.getdirectcontent()); column.addelement(footer); column.setsimplecolumn (0, 0, 630, 80); column.go(); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -