我的Java项目中的iText库出现问题,因为在将html代码段转换为PDF文件时,它显然不支持删除线文本。我的Web应用程序输入文本字段将其内部文本转换为html,并在此部分代码中进行处理:
private List<Element> parseHtml(String html) throws Exception{
// CSS
CSSResolver cssResolver = new StyleAttrCSSResolver();
// HTML
CssAppliers cssAppliers = new CssAppliersImpl(FontFactory.getFontImp());
HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
htmlContext.autoBookmark(false);
htmlContext.setImageProvider(new EmbeddedImageProvider());
// Pipelines
ElementList elements = new ElementList();
ElementHandlerPipeline end = new ElementHandlerPipeline(elements, null);
HtmlPipeline htmlPipeline = new HtmlPipeline(htmlContext, end);
CssResolverPipeline cssPipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
// XML Worker
XMLWorker worker = new XMLWorker(cssPipeline, true);
XMLParser p = new XMLParser(worker);
p.parse(new ByteArrayInputStream(html.getBytes()));
return elements;
}
在处理's'作为删除线标记时,它将忽略它并在对象下划线。我唯一能找到的解决方案是像这样实现它:
Chunk strikethrough = new Chunk("Strikethrough.");
strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location
doc.addStrike(strikethrough);
您能否建议如何最好地将其实施到我之前的代码中?谢谢