当我使用AutoDetectParser解析PDF或Word文档时,“li”,“ul”标签被转换为“p”标签。我需要确切的HTML内容,包括PDF或Word文档。
我试过以下几种方式:
ToHTMLContentHandler textHandler = new ToHTMLContentHandler();
Metadata metadata = new Metadata();
Parser parser = new AutoDetectParser();
ParseContext context = new ParseContext();
context.set(HtmlMapper.class, new IdentityHtmlMapper());
parser.parse(in, textHandler, metadata, context);
SAXTransformerFactory factory = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
TransformerHandler handler = factory.newTransformerHandler();
handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "no");
handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "utf-8");
handler.setResult(new StreamResult(writer));
System.out.println(handler.toString());
return handler;
但是“li”标签已被“p”标签替换为类,但在解析的HTML输出中看不到CSS样式。
感谢任何帮助。