文字正常显示但没有提取出来图片 也没显示图片
以下是代码
- import org.apache.poi.xwpf.converter.core.BasicURIResolver;
- import org.apache.poi.xwpf.converter.core.FileImageExtractor;
- import org.apache.poi.xwpf.converter.core.FileURIResolver;
- import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;
- import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;
- import org.apache.poi.xwpf.usermodel.XWPFDocument;
-
- import java.io.*;
- import java.util.List;
-
- public class DocxTransUtil {
-
- public static void trans2htm(String docxfile)throws Throwable{
- long startTime = System.currentTimeMillis();
- String fileName = docxfile.substring(docxfile.lastIndexOf("\\")+1);
- String file = fileName.substring(0,fileName.lastIndexOf("."));
- String path = DocxTransUtil.class.getResource("/").getPath()+"News/";
- XWPFDocument document = new XWPFDocument(new FileInputStream(docxfile));
- XHTMLOptions options = XHTMLOptions.create().indent(4);
- // 导出图片
- File imageFolder = new File(path);
- options.setExtractor(new FileImageExtractor(imageFolder));
- // URI resolver word的html中图片的目录路径
- options.URIResolver(new FileURIResolver(imageFolder));
- File outFile = new File(path+file+".html");
- outFile.getParentFile().mkdirs();
- OutputStream out = new FileOutputStream(outFile);
- XHTMLConverter.getInstance().convert(document, out, options);
- System.out.println(path+"Generate " + path + " with " + (System.currentTimeMillis() - startTime) + " ms.");
-
- }
-
- }