Use itext. jar in Java to generate WORD Documents

Source: Internet
Author: User
Tags image png

 

Import java. Io. fileoutputstream;
Import java. Io. ioexception;

Import com. lowagie. Text. Document;
Import com. lowagie. Text. extends entexception;
Import com. lowagie. Text. Font;
Import com. lowagie. Text. headerfooter;
Import com. lowagie. Text. pagesize;
Import com. lowagie. Text. Paragraph;
Import com. lowagie. Text. phrase;
Import com. lowagie. Text. rectangle;
Import com.lowagie.text=. basefont;
Import com. lowagie. Text. rtf. rtfwriter2;

Public class rules {
Public static void main (string [] ARGs) throws disable entexception, ioexception {
Document document = new document (pagesize. A4 );
Rtfwriter2.getinstance (document, new fileoutputstream ("E:/1.doc "));
Document. open ();

// Add a header
Headerfooter header = new headerfooter (new phrase ("Header"), false );
Header. setalignment (rectangle. align_center );
Document. setheader (header );

// Add a footer
Headerfooter footer = new headerfooter (new phrase ("footer"), false );
Footer. setalignment (rectangle. align_center );
Document. setfooter (footer );

// Set the Chinese font
Basefont bfchinese = basefont. createfont ("stsongstd-light", "UniGB-UCS2-H", basefont. not_embedded );
Font contextfont = new font (bfchinese, 10, Font. Normal );
Paragraph context = new paragraph ("");
Context. setfont (contextfont );
// Image PNG = image. getinstance ("D:/busy.gif ");
// PNG. setabsoluteposition (0, 0 );
// PNG. setalignment (image. textwrap );

 

Context. Add ("content 1 ");
// Context. Add (new phrase (New chunk (PNG, 0, 0, true )));
Context. Add ("content 2 ");
// Context. Add (new phrase (New chunk (PNG, 0, 0, true )));
Context. Add ("content 3 ");
Document. Add (context );
Document. Close ();
}
 
}

 

Original post address: http://housen1987.iteye.com/blog/1335036

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.