我有以下html
<div style="border: 2px solid black; padding: 5px;">
<p align="CENTER">test1</p>
<p align="CENTER">test2</p>
</div>
并使用open office lib
将其转换为pdf <dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.1</version>
</dependency>
和这个功能
public synchronized static byte[] htmlToPdf(String html) throws Exception {
ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
DefaultDocumentFormatRegistry defaultDocumentFormatRegistry = new DefaultDocumentFormatRegistry();
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(IOUtils.toInputStream(html, Charset.forName("UTF-8")), defaultDocumentFormatRegistry.getFormatByFileExtension("html"), pdfOutputStream, defaultDocumentFormatRegistry.getFormatByFileExtension("pdf"));
connection.disconnect();
return pdfOutputStream.toByteArray();
}
我们正在进行这种翻转
@linux-9jgs:~> soffice --version
LibreOffice 4.3.7.2 430m0(Build:2)
但是在pdf中每行都有它自己的边框,在浏览器中html看起来没问题
我记得以前版本的开放式办公室工作正常