-----------------------------------------------------------------------------
| C | d | E |
-A B ---------------------------------------------------------------- |
| C1 | C2 | d1 | D2 | E1 | E2 |
| -------------------------------------------------------------------------- |
Public static void main (string [] ARGs ){
Document docu = new document (pagesize. A4, 5, 5, 10, 5 );
Try {
Fileoutputstream Fos = new fileoutputstream ("F: // a.pdf ");
Pdfptable table = new pdfptable (8 );
Using writer. getinstance (Docu, FOS );
Docu. open ();
// Content font
Basefont bfcomic = basefont. createfont ("stsong-light ",
"UniGB-UCS2-H", basefont. not_embedded); // Chinese supported
Font font = new font (bfcomic, 12, Font. Normal); // large title
Font font2 = new font (bfcomic, 10, Font. Normal); // subtitle
// C (internal table)
Pdfptable begtable = new pdfptable (2 );
Export pcell begcell = new export pcell (new paragraph ("initial balance", font ));
Begcell. sethorizontalalignment (element. align_center );
Begcell. setcolspan (2 );
Begtable. addcell (begcell );
// D (internal table)
Pdfptable ytable = new pdfptable (2 );
Export pcell ycell = new export pcell (new paragraph ("accumulative amount", font ));
Ycell. sethorizontalalignment (element. align_center );
Ycell. setcolspan (2 );
Ytable. addcell (ycell );
// E (internal table)
Pdfptable endtable = new pdfptable (2 );
Export pcell endcell = new export pcell (new paragraph ("Final Balance", font ));
Endcell. sethorizontalalignment (element. align_center );
Endcell. setcolspan (2 );
Endtable. addcell (endcell );
// The header of the first line
Export pcell ACC = new export pcell (new paragraph ("Subject code", font ));
ACC. setrowspan (2); // merge rows
// Center both horizontally and vertically
ACC. sethorizontalalignment (element. align_center );
ACC. setverticalalignment (element. align_middle );
Pdfpcell name = new pdfpcell (new paragraph ("Subject name", font ));
Name. setrowspan (2 );
// Center both horizontally and vertically
Name. sethorizontalalignment (element. align_center );
Name. setverticalalignment (element. align_middle );
// Column C
Export pcell cell2 = new pdfpcell (begtable );
Cell2.sethorizontalalignment (element. align_center );
Cell2.setcolspan (2 );
// Column D
Export pcell cell3 = new export pcell (ytable );
Cell3.sethorizontalalignment (element. align_center );
Cell3.setcolspan (2 );
// Column E
Export pcell cell4 = new export pcell (endtable );
Cell4.sethorizontalalignment (element. align_center );
Cell4.setcolspan (2 );
Table. addcell (ACC); //
Table. addcell (name); // B
Table. addcell (cell2 );
Table. addcell (cell3 );
Table. addcell (cell4 );
// The title of the second row
Table. addcell (new paragraph ("C1", font2 ));
Table. addcell (new paragraph ("C2", font2 ));
Table. addcell (new paragraph ("d1", font2 ));
Table. addcell (new paragraph ("D2", font2 ));
Table. addcell (new paragraph ("E1", font2 ));
Table. addcell (new paragraph ("E2", font2 ));
Docu. Add (table );
Docu. Close ();
} Catch (exception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}