/**
* word和txt文件转换图片
*
* @param inputStream
* @return
* @throws Exception
*/
private static List<BufferedImage> wordToImage(InputStream inputStream) throws Exception {
try {
Document doc = new Document(inputStream);
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
options.setPrettyFormat(true);
options.setUseAntiAliasing(true);
options.setUseHighQualityRendering(true);
int pageCount = doc.getPageCount();
List<BufferedImage> imageList = new ArrayList<>();
for (int i = 0; i < pageCount; i++) {
OutputStream output = new ByteArrayOutputStream();
options.setPageSet(new PageSet(i));
doc.save(output, options);
ImageInputStream imageInputStream = ImageIO.createImageInputStream(parse(output));
imageList.add(ImageIO.read(imageInputStream));
}
return imageList;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
public static ByteArrayInputStream parse(OutputStream stream) {
ByteArrayOutputStream out = (ByteArrayOutputStream) stream;
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
return in;
}