这篇文章将为大家详细讲解有关java怎么修改文档第一页为不同的页面,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
Java的基本数据类型分为:1、整数类型,用来表示整数的数据类型。2、浮点类型,用来表示小数的数据类型。3、字符类型,字符类型的关键字是“char”。4、布尔类型,是表示逻辑值的基本数据类型。
1、主要步骤
加载Word测试文档
获取第一节,设置首页页眉页脚不同
获取首页页眉,清除首页页眉默认的段落格式
重新添加段落,添加图片到段落,设置图片格式
2、实例
import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.TextWrappingStyle;
import com.spire.doc.documents.VerticalOrigin;
import com.spire.doc.fields.DocPicture;
public class DifferentPageBackground1 {
public static void main(String[] args) {
//加载Word测试文档
Document doc = new Document();
doc.loadFromFile("测试.docx");
//获取第一节
Section section = doc.getSections().get(0);
//设置首页页眉页脚不同
section.getPageSetup().setDifferentFirstPageHeaderFooter(true);
//获取首页页眉
HeaderFooter firstpageheader = section.getHeadersFooters().getFirstPageHeader();
firstpageheader.getParagraphs().clear();//清除首页页眉默认的段落格式(若不清除原有段落中的格式,生成的文档效果中页眉中有一条横线)
//重新添加段落
Paragraph firstpara= firstpageheader.addParagraph();
//添加图片到段落,设置图片格式
DocPicture pic0 = firstpara.appendPicture("1.png");
pic0.setTextWrappingStyle(TextWrappingStyle.Behind);
pic0.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
pic0.setVerticalOrigin(VerticalOrigin.Top_Margin_Area);
//获取页面宽度、高度
int width = (int) section.getPageSetup().getPageSize().getWidth();
int height = (int) section.getPageSetup().getPageSize().getHeight();
//设置图片大小,铺满页面
pic0.setWidth(width);
pic0.setHeight(height);
//同理设置其他页面的页眉
HeaderFooter otherheader = section.getHeadersFooters().getHeader();
otherheader.getParagraphs().clear();
Paragraph otherpara = otherheader.addParagraph();
DocPicture pic1 = otherpara.appendPicture("2.png");
pic1.setTextWrappingStyle(TextWrappingStyle.Behind);
pic1.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
pic1.setVerticalOrigin(VerticalOrigin.Top_Margin_Area);
pic1.setWidth(width);
pic1.setHeight(height);
//保存文档
doc.saveToFile("result.docx",FileFormat.Docx_2013);
doc.dispose();
}
}
关于“java怎么修改文档第一页为不同的页面”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.py.cn/java/jichu/27184.html