Commit 60639b81 by 吴博

feat: [1004879] 口算批改

parent 4822c556
......@@ -12,6 +12,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import com.lowagie.text.Rectangle;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
......@@ -107,6 +108,44 @@ public class WordUtils {
return outPath;
}
public static String create(List<WordPO> wordPOs, Integer width, Integer height) throws FileException {
LOGGER.info("【WORD】创建自定义尺寸WORD文档,<START>");
if (ListUtils.isEmpty(wordPOs)) {
return null;
}
String outPath = null;
Document document = null;
OutputStream os = null;
RtfWriter2 rtfWriter2 = null;
try {
// 输出路径
outPath = FilePathConstant.WORD + UUIDUitl.taskName() + ".doc";
FileUtils.creatFiles(outPath);
// 创建输出流
os = new FileOutputStream(new File(outPath));
// 初始化文档
// 创建文档实例
// 创建word文档,并设置纸张的大小
float rate = 2.83333f;
width = Math.round(width * rate);
height = Math.round(height * rate);
document = new Document(new Rectangle(width, height));
rtfWriter2 = RtfWriter2.getInstance(document, os);
document.open();
// 添加内容添加PDF实例中
addChunks(wordPOs, document);
} catch (Exception e) {
FileUtils.deleteFile(outPath);
LOGGER.error("【WORD】创建WORD文档失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_CONTENT_ERROR, e.getMessage());
} finally {
close(document, os, rtfWriter2);
}
LOGGER.info("【WORD】创建WORD文档,<END>");
return outPath;
}
/**
* 添加内容到PDF中
*
......@@ -142,6 +181,9 @@ public class WordUtils {
// 段落
Paragraph paragraph = null;
Font font = WordFontUtils.getByType(wordChunkPO.getFont());
if (wordChunkPO.getFontSize() > 0) {
font.setSize(wordChunkPO.getFontSize());
}
if (wordChunkPO.isLeanding()) {
paragraph = new Paragraph(wordChunkPO.getText(), font);
paragraph.setLeading(wordChunkPO.getLeading() > 0 ? wordChunkPO.getLeading() : Float.NaN);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment