Itext merge columns and rows

Source: Internet
Author: User

-----------------------------------------------------------------------------

| 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 ();

}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.