Optimize image export
This commit is contained in:
parent
3c00d47407
commit
3101cf0e42
|
@ -40,9 +40,22 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.time.format.DateTimeParseException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.apache.poi.xwpf.usermodel.Document.*;
|
||||
|
||||
public class WordBuilder {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class);
|
||||
private static final Map<String, Integer> IMAGE_TYPE_MAP = Stream.of(new Object[][] {
|
||||
{".jpeg", PICTURE_TYPE_JPEG},
|
||||
{".jpg", PICTURE_TYPE_JPEG},
|
||||
{".png", PICTURE_TYPE_PNG},
|
||||
{".gif", PICTURE_TYPE_GIF},
|
||||
{".tiff", PICTURE_TYPE_TIFF},
|
||||
{".bmp", PICTURE_TYPE_BMP},
|
||||
{".wmf", PICTURE_TYPE_WMF}
|
||||
}
|
||||
).collect(Collectors.toMap(objects -> (String)objects[0], o -> (Integer)o[1]));
|
||||
|
||||
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, Object, XWPFParagraph>> options = new HashMap<>();
|
||||
private CTAbstractNum cTAbstractNum;
|
||||
|
@ -148,16 +161,9 @@ public class WordBuilder {
|
|||
XWPFRun run = paragraph.createRun();
|
||||
String imageId = ((Map<String, String>)item).get("id");
|
||||
String fileName = ((Map<String, String>)item).get("name");
|
||||
int format = 0;
|
||||
if (fileName.endsWith(".jpeg") || fileName.endsWith(".jpg")) {
|
||||
format = org.apache.poi.xwpf.usermodel.Document.PICTURE_TYPE_JPEG;
|
||||
} else if (fileName.endsWith(".png")) {
|
||||
format = org.apache.poi.xwpf.usermodel.Document.PICTURE_TYPE_PNG;
|
||||
} else if (fileName.endsWith(".gif")) {
|
||||
format = org.apache.poi.xwpf.usermodel.Document.PICTURE_TYPE_GIF;
|
||||
} else if (fileName.endsWith(".tiff")) {
|
||||
format = org.apache.poi.xwpf.usermodel.Document.PICTURE_TYPE_TIFF;
|
||||
}
|
||||
int format;
|
||||
String fileExtension = fileName.substring(fileName.lastIndexOf("."));
|
||||
format = IMAGE_TYPE_MAP.getOrDefault(fileExtension, 0);
|
||||
try {
|
||||
FileInputStream image = new FileInputStream(environment.getProperty("file.storage") + imageId);
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(new File(environment.getProperty("file.storage") + imageId));
|
||||
|
|
Loading…
Reference in New Issue