您好!使用spire doc for java 在页眉左侧位置如何插入图片时,使图片置于顶层或删除相同位置的图片?
如何去掉字体黑色底纹?
private static void InsertPicAndCleanColor(String filePath, String picPath) {
Document document = new Document(filePath);
HeaderFooter header = document.getSections().get(0).getHeadersFooters().getHeader();
Paragraph headerParagraph = header.getParagraphs().get(0);
DocPicture newPicture = new DocPicture(document);
newPicture.loadImage(picPath);
// if you want to delete the original pic
// for (DocumentObject object : (Iterable<DocumentObject>) headerParagraph.getChildObjects()) {
// if (object instanceof DocPicture) {
// headerParagraph.getChildObjects().remove(object);
// break;
// }
// }
// if you want to move the new pic to top
newPicture.setTextWrappingStyle(TextWrappingStyle.In_Front_Of_Text);
headerParagraph.getChildObjects().add(newPicture);
// clean the black background
Paragraph textParagraph = document.getSections().get(0).getParagraphs().get(0);
textParagraph.getListFormat().getCurrentListLevel().getCharacterFormat().setHighlightColor(null);
document.saveToFile("res.docx", FileFormat.Docx_2013);
System.out.println("okk!");
}
for (int j = 0; j < document.getSections().getCount(); j++) {
Section section = document.getSections().get(j);
for (int i = 0; i < section.getParagraphs().getCount(); i++) {
Paragraph textParagraph = section.getParagraphs().get(i);
if (!"".equals(textParagraph.getListFormat().getCurrentListLevel())
&& textParagraph.getListFormat().getCurrentListLevel() != null) {
textParagraph.getListFormat().getCurrentListLevel().getCharacterFormat().setHighlightColor(null);
}
for (DocumentObject object : (Iterable<DocumentObject>) textParagraph.getChildObjects()) {
if (object instanceof TextRange) {
TextRange range = (TextRange) object;
if (range.getCharacterFormat().getHighlightColor().equals(Color.BLACK)) {
range.getCharacterFormat().setHighlightColor(null);
}
} else if (object instanceof Footnote) {
Footnote note = (Footnote) object;
if (note.getCharacterFormat().getHighlightColor().equals(Color.BLACK)) {
note.getCharacterFormat().setHighlightColor(null);
}
}
}
}
}
List<DocPicture> pictures = new List<DocPicture>();
... ...
... ...
else if (object instanceof DocPicture) {
pictures.add((DocPicture) object);
}
... ...
for (DocPicture docPicture : pictures) {
docPicture.getOwner().getChildObjects().remove(docPicture);
}