Note that there are some explanatory texts on larger screens.

plurals
  1. POI need Apache POI Pictures converted from a word document to a html file
    primarykey
    data
    text
    <p>I have some code that uses the Java Apache POI library to open a Microsoft word document and convert it to html, using the the Apache POI and it also gets the byte array data of images on the document. But I need to convert this information to html to write out to an html file. Any hints or suggestions would be appreciated. Keep in mind that I am a desktop dev developer and not a web programmer, so when you make suggestions, please remember that. The code below gets the image.</p> <pre><code> private void parseWordText(File file) throws IOException { FileInputStream fs = new FileInputStream(file); doc = new HWPFDocument(fs); PicturesTable picTable = doc.getPicturesTable(); if (picTable != null){ picList = new ArrayList&lt;Picture&gt;(picTable.getAllPictures()); if (!picList.isEmpty()) { for (Picture pic : picList) { byte[] byteArray = pic.getContent(); pic.suggestFileExtension(); pic.suggestFullFileName(); pic.suggestPictureType(); pic.getStartOffset(); } } } </code></pre> <p>Then the code below this converts the document to html. Is there a way to add the byteArray to the ByteArrayOutputStream in the code below?</p> <pre><code>private void convertWordDoctoHTML(File file) throws ParserConfigurationException, TransformerConfigurationException, TransformerException, IOException { HWPFDocumentCore wordDocument = null; try { wordDocument = WordToHtmlUtils.loadDoc(new FileInputStream(file)); } catch (IOException ex) { Exceptions.printStackTrace(ex); } WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()); wordToHtmlConverter.processDocument(wordDocument); org.w3c.dom.Document htmlDocument = wordToHtmlConverter.getDocument(); NamedNodeMap node = htmlDocument.getAttributes(); ByteArrayOutputStream out = new ByteArrayOutputStream(); DOMSource domSource = new DOMSource(htmlDocument); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.transform(domSource, streamResult); out.close(); String result = new String(out.toByteArray()); acDocTextArea.setText(newDocText); htmlText = result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload