diff --git a/.DS_Store b/.DS_Store index 03b43c0..60c5c91 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/WebContent/.DS_Store b/WebContent/.DS_Store index ae90684..79e4cf1 100644 Binary files a/WebContent/.DS_Store and b/WebContent/.DS_Store differ diff --git a/WebContent/WEB-INF/.DS_Store b/WebContent/WEB-INF/.DS_Store index b218553..dc30cab 100644 Binary files a/WebContent/WEB-INF/.DS_Store and b/WebContent/WEB-INF/.DS_Store differ diff --git a/WebContent/WEB-INF/lib/poi-ooxml-3.8-20120326.jar b/WebContent/WEB-INF/lib/poi-ooxml-3.8-20120326.jar index 9175c16..ca21f55 100755 Binary files a/WebContent/WEB-INF/lib/poi-ooxml-3.8-20120326.jar and b/WebContent/WEB-INF/lib/poi-ooxml-3.8-20120326.jar differ diff --git a/src/com/albert/test/Test.java b/src/com/albert/test/Test.java new file mode 100644 index 0000000..f3ff669 --- /dev/null +++ b/src/com/albert/test/Test.java @@ -0,0 +1,25 @@ +/** + * + */ +package com.albert.test; + +import org.apache.poi.xwpf.converter.DocxConverter; + +/** +* @ClassName: Test +* @Description: +* @author albert +* @date 2017年9月19日 下午4:56:28 +* +*/ +public class Test { + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + DocxConverter.convert("/Users/albert/Desktop/test.docx", "/Users/albert/Desktop/test.html"); + } + +} diff --git a/src/org/apache/poi/hwpf/converter/DocConverter.java b/src/org/apache/poi/hwpf/converter/DocConverter.java index f1fca8e..8396a78 100755 --- a/src/org/apache/poi/hwpf/converter/DocConverter.java +++ b/src/org/apache/poi/hwpf/converter/DocConverter.java @@ -806,12 +806,12 @@ protected void processImage(Element parent, CharacterRun cr ){ try { // TWIPS_PER_INCH/ - out = new FileOutputStream(new File(output.concat(File.separator).concat(fileName))); + File f= new File(output.concat(File.separator).concat(fileName)); + out = new FileOutputStream(f); pic.writeImageContent(out); Element img = htmlDocumentFacade.getDocument().createElement("img"); - String[] arr = output.split("/"); - String uri = arr[arr.length-3].concat(File.separator).concat(arr[arr.length-2]).concat(File.separator).concat(arr[arr.length-1]).concat(File.separator).concat(fileName); - img.setAttribute("src",uri ); + String uri = f.getParent().replace(f.getParentFile().getParentFile().getParentFile().getParentFile().getPath(), "").concat(File.separator).concat(fileName); + img.setAttribute("src",uri.substring(1) ); if(pic.getWidth() > 600) img.setAttribute("style", "width: 600px;"); Element imgBlock = htmlDocumentFacade.createBlock(); diff --git a/src/org/apache/poi/xwpf/converter/DocxConverter.java b/src/org/apache/poi/xwpf/converter/DocxConverter.java index 984d0d3..5ad21e1 100755 --- a/src/org/apache/poi/xwpf/converter/DocxConverter.java +++ b/src/org/apache/poi/xwpf/converter/DocxConverter.java @@ -93,16 +93,13 @@ public DocxConverter( String filePath, String output) throws IOException, Invali Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); StringUtil.getFilePath(""); - {// create image folder int pos = output.lastIndexOf("."); imgFolderPath = output.substring(0, pos).concat(File.separator).concat(IMG_FOLDER); File folder = new File(imgFolderPath); if(!folder.canRead()) folder.mkdirs(); - folder = null; - } - imgPath = StringUtil.getFileName(filePath, false).concat(File.separator).concat(IMG_FOLDER); + imgPath = folder.getParent().replace(folder.getParentFile().getParentFile().getParentFile().getParentFile().getPath(), "").concat(File.separator).concat(IMG_FOLDER); OPCPackage container = OPCPackage.open(filePath); @@ -327,7 +324,6 @@ private void processParagraphMulti(XWPFParagraph paragraph, Element page, boole } private void processRun(Element container, XWPFRun r) throws IOException { - List pics = r.getEmbeddedPictures(); if(!pics.isEmpty()){ processImage( container, pics);