Я использую Apache POI 4.0.0 для конвертации файлов формата .doc в html. Большинство файлов конвертируются отлично, и меня устраивает результат. Но есть какая то часть файлов, которые конвертируются не полностью.
private static String ProcessingDoc(File doc, String imagedir) throws IOException, ParserConfigurationException, TransformerConfigurationException, TransformerFactoryConfigurationError {
FileInputStream in = new FileInputStream(doc);
HWPFDocument doc_file = new HWPFDocument(in);
Document html_file = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
WordToHtmlConverter converter = new WordToHtmlConverter(html_file);
converter.setPicturesManager(new PicturesManager() {
@Override
public String savePicture(byte[] content, PictureType pictureType, String suggestedName, float widthInches,
float heightInches) {
File imgFile = new File(getParentDirectory(doc));
if(!imgFile.exists()){
imgFile.mkdirs();
}
try {
FileOutputStream out = new FileOutputStream(imagedir+"/" + suggestedName);
out.write(content);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return suggestedName;
}
});
converter.processDocument(doc_file);
StringWriter stringWriter = new StringWriter();
Transformer transformer;
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
transformer.setOutputProperty( OutputKeys.METHOD, "html" );
try {
transformer.transform(
new DOMSource( converter.getDocument() ),
new StreamResult( stringWriter ) );
} catch (TransformerException e) {
e.printStackTrace();
}
return stringWriter.toString();
}
Т.е. итоговый html файл обрывается просто на произвольном месте. К примеру вот так:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">.b1{white-space-collapsing:preserve;}
....Здесь идет текст...
И вот это последние строки в документе.
</p>
</td>
</tr>
<tr class="r1">
<td class="td5">
<p class="p14">
<span>ИДФилиала</span>
</p>
</td><td class="td6">
Ошибок при конвертации не возникает, но файл обрезается. Что я делаю не правильно? Может нужны какие то настройки библиотеки? Спасибо за ответ!
Современные инструменты для криптотрейдинга: как технологии помогают принимать решения
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости