add 公式转换图片url

This commit is contained in:
lijiarao
2024-03-20 17:20:30 +08:00
parent c18d038143
commit 93194850d4
4 changed files with 34 additions and 24 deletions
@@ -1,5 +1,8 @@
package com.jero.modules.split.service.impl;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser;
@@ -18,10 +21,7 @@ import com.jero.modules.split.enums.SplitFileTypeTypeEnum;
import com.jero.modules.split.mapper.SarFileSplitMenuEOMapper;
import com.jero.modules.split.service.IFileSplitItemsEOService;
import com.jero.modules.split.service.ISarFileSplitItemsValEOService;
import com.jero.modules.split.util.AsposeUtil;
import com.jero.modules.split.util.FileSplitUtils;
import com.jero.modules.split.util.ParagraphChildOrderManager;
import com.jero.modules.split.util.ReadWordTable;
import com.jero.modules.split.util.*;
import com.jero.modules.split.vo.TitleNumberVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -94,6 +94,8 @@ public class FileSpiltService {
private String filePathCos;
@Value("${jero.splitUrl}")
private String splitUrl;
@Value("${jero.mathToImgUrl}")
private String mathToImgUrl;
/**
* 判断附录正则
*/
@@ -178,16 +180,6 @@ public class FileSpiltService {
XWPFDocument doc = new XWPFDocument(is);
// 获取文档中的图片
List<XWPFPictureData> allPictures = doc.getAllPictures();
// 遍历图片并处理数学公式
for (XWPFPictureData pictureData : allPictures) {
String contentType = pictureData.getPackagePart().getContentType();
System.out.println(contentType);
// 判断图片类型是否为数学公式
if (contentType.equals(PictureType.EMF.getExtension())) {
// 处理数学公式,你可以在这里添加自己的逻辑
System.out.println("Found a math equation!");
}
}
//获得序号标题和无标题序号
TitleNumberVO titleNumberVO = AsposeUtil.getNumber(is1);
//TitleNumberVO titleNumberVO = new TitleNumberVO();
@@ -221,18 +213,30 @@ public class FileSpiltService {
//} else
if (child instanceof CTOMath) {
CTOMath ctoMath = (CTOMath) child;
//stringBuilder.append(ctoMath.xmlText());
// 处理word中存在的公式成mathML格式
//String imageName = OmmlUtils.convertOmathToPng(ctoMath.xmlText());
//if (messageList.size() > 0) {
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, imageName);
//}
String xmlText = ctoMath.xmlText().replaceAll("xml-fragment","m:oMath");
Map<String, Object> map = new HashMap<>();
map.put("encode", xmlText);
String post = HttpRequest.post(mathToImgUrl)
.header(Header.CONTENT_TYPE, "application/json")
.body(xmlText)
.execute().body();
//String post = HttpUtil.post(mathToImgUrl, map);
if (messageList.size() > 0) {
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
}
} else if (child instanceof CTOMathPara) {
CTOMathPara ctoMathPara = (CTOMathPara) child;
//String imageName = OmmlUtils.convertOmathToPng(ctoMathPara.xmlText());
//if (messageList.size() > 0) {
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, imageName);
//}
String xmlText = ctoMathPara.xmlText().replaceAll("xml-fragment","m:oMath");;
Map<String,Object> map = new HashMap<>();
map.put("encode",xmlText);
String post = HttpRequest.post(mathToImgUrl)
.header(Header.CONTENT_TYPE, "application/json")
.body(xmlText)
.execute().body();
//String post = HttpUtil.post(mathToImgUrl, map);
if (messageList.size() > 0) {
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
}
}
}