Я могу порекомендовать JodConverter, он использует OpenOffice в режиме без головы
1 установка openoffice (для linux "zypper install libreoffice")
2 WIN поместил его в переменную пути, чтобы "soffice" мог запускаться везде, для меня это был "C: \ Program Files (x86) \ LibreOffice 4 \ program"
3 LINUX убедитесь, что пользователь, который запускает процесс Java, владеет своим домашним каталогом, потому что
openoffice должен хранить там конфиги, для меня tomcat запустил процесс, но его домашний каталог принадлежал root
4 добавьте jodconverter-lib в ваш проект java
<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.1</version>
</dependency>
1012 * новообращенный *
// ensure open office is running
String[] commands = new String[] {"soffice","--headless","--accept=socket,host=localhost,port=8100;urp;"};
Runtime.getRuntime().exec(commands);
// convert
String html = "<div>hey there</div>";
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();
byte[] pdfBytes = pdfOutputStream.toByteArray();