public class CreateWordDemo
{
public void createDocContext(String file)
throws DocumentException,IOException {
//
设置纸张大小
Document document = new
Document(PageSize.A4);
//
建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中 RtfWriter2.getInstance(document, new
FileOutputStream(file));
document.open();
//
设置中文字体
BaseFont bfChinese =
BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H",
BaseFont.NOT_EMBEDDED);
//
标题字体风格
Font titleFont = new Font(bfChinese, 12,
Font.BOLD);
//
正文字体风格
Font contextFont = new Font(bfChinese, 10,
Font.NORMAL);
Paragraph title = new
Paragraph("标题");
//
设置标题格式对齐方式
title.setAlignment(Element.ALIGN_CENTER)