IElementNode 的 tag.getChildren().add(new HtmlText(italicContent));没有这个方法
时间: 2024-03-03 09:53:21 浏览: 12
非常抱歉,我的回答有误。在 iText7 版本 7.1.5 和 html2pdf 版本 2.0.2 中,IElementNode 接口并没有 getChildren() 方法。为了将处理后的内容添加到标签节点中,我们可以使用以下方法:
1. 在 ChineseItalicTagWorker 中添加一个字段,用于保存标签节点的子元素列表:
```
private final List<IElement> children = new ArrayList<>();
```
2. 在 processContent 方法中,将处理后的内容添加到子元素列表中:
```
String italicContent = "<i>" + content.replaceAll("[\\u4e00-\\u9fa5]+", "<em>$0</em>") + "</i>";
children.add(new HtmlText(italicContent));
```
3. 在 getElementResult 方法中,创建新的标签节点,并将子元素列表添加到标签节点中:
```
public IPropertyContainer getElementResult() {
IPropertyContainer result = new Div();
for (IElement child : children) {
result.addChild(child);
}
return result;
}
```
这样就可以实现将处理后的内容添加到标签节点中了。再次感谢您指出我的错误。