public void CreateDocument() throws FileNotFoundException, DocumentException {
FileOutputStream out = new FileOutputStream("d:\\demo.doc");
//设置纸张大小
Document document = new Document(PageSize.A4);
//建立一个书写器,与document对象关联
RtfWriter2.getInstance(document, out);
document.open();
//章节一
Chapter chapter1 = new Chapter(1);
chapter1.add(new Paragraph("Hello World1"));
//章节二
Chapter chapter2 = new Chapter(2);
chapter2.add(new Paragraph("Hello World2"));
//章节三
Chapter chapter3 = new Chapter(3);
chapter3.add(new Paragraph("Hello World3"));
//将章节加入document中
document.add(chapter1);
//将章节二纵向显示
document.setPageSize(PageSize.A4.rotate());
document.add(chapter2);
//将章节三还原成横向
document.setPageSize(PageSize.A4);
document.add(chapter3);
document.close();
}
使用iText 生成 包含横 纵页面的word文件
最新推荐文章于 2023-06-21 15:39:11 发布