getDoc网上专用接口修改1
This commit is contained in:
@@ -734,7 +734,26 @@ public class TypesetController {
|
||||
map.put("doi", typesetInfo.getDoi());
|
||||
map.put("topic", typesetInfo.getTopic());
|
||||
map.put("articletitle", typesetInfo.getInfo_title().replace("<b>", "").replace("</b>", "").replace("<i>", "").replace("</i>", ""));
|
||||
map.put("author", typesetInfo.getAuthor().replace("<b>", "").replace("</b>", "").replace("<i>", "").replace("</i>", ""));
|
||||
|
||||
String author = typesetInfo.getAuthor();
|
||||
String[] s_author = author.split("</q>");
|
||||
ParagraphRenderData author_p = new ParagraphRenderData();
|
||||
// for (String i:s_author){
|
||||
// if(i.equals("")){
|
||||
// continue;
|
||||
// }
|
||||
// String[] cache_author = i.split("<q>");
|
||||
// String au = cache_author[0];
|
||||
// String bu = cache_author[1];
|
||||
// Style ca_sty = new Style();
|
||||
// ca_sty.setVertAlign("superscript");
|
||||
// author_p.addText(new TextRenderData(au.replace("<i>", "").replace("</i>", "")));
|
||||
// author_p.addText(new TextRenderData(bu.replace("<i>", "").replace("</i>", ""),ca_sty));
|
||||
// }
|
||||
//
|
||||
// map.put("author",author_p);
|
||||
|
||||
map.put("author", typesetInfo.getAuthor().replace("<b>", "").replace("</b>", "").replace("<i>", "").replace("</i>", ""));
|
||||
map.put("authoraddress", typesetInfo.getAuthorAddress().replace("<b>", "").replace("</b>", "").replace("<i>", "").replace("</i>", ""));
|
||||
map.put("corresponding", typesetInfo.getAuthorCorresponding().replace("<b>", "").replace("</b>", "").replace("<i>", "").replace("</i>", ""));
|
||||
map.put("coremail", typesetInfo.getAuthorCorrespondingEmail().replace("<b>", "").replace("</b>", "").replace("<i>", "").replace("</i>", ""));
|
||||
@@ -1150,7 +1169,7 @@ public class TypesetController {
|
||||
}
|
||||
}
|
||||
picMap.put(imageName,lastParagraphText);
|
||||
System.out.println(pictureId +"\t|" + imageName + "\t|" + lastParagraphText);
|
||||
// System.out.println(pictureId +"\t|" + imageName + "\t|" + lastParagraphText);
|
||||
//获取word文本中所有的图片
|
||||
// List<XWPFPictureData> allPictures = xdoc.getAllPictures();
|
||||
//遍历照片
|
||||
@@ -1166,13 +1185,13 @@ public class TypesetController {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(filePicture);
|
||||
fileOutputStream.write(data,0,data.length);
|
||||
fileOutputStream.close();
|
||||
System.out.println("执行结束了");
|
||||
// System.out.println("执行结束了");
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("picNameList===========>"+picNameList);
|
||||
System.out.println("picMap===========>"+picMap);
|
||||
// System.out.println("picNameList===========>"+picNameList);
|
||||
// System.out.println("picMap===========>"+picMap);
|
||||
//2.获取按模板新生成的文档添加图片
|
||||
File newFile = new File(this.NEW_BASE_DIR + newFileName);
|
||||
FileInputStream newFis = new FileInputStream(newFile);
|
||||
@@ -1184,20 +1203,20 @@ public class TypesetController {
|
||||
Document doc = new Document();
|
||||
doc.loadFromFile(this.NEW_BASE_DIR + newFileName);
|
||||
Section sec = doc.getSections().get(0);
|
||||
System.out.println("sec=================>"+sec);
|
||||
// System.out.println("sec=================>"+sec);
|
||||
String text = doc.getText();
|
||||
System.out.println("text=================>"+text);
|
||||
// System.out.println("text=================>"+text);
|
||||
Paragraph para = sec.getParagraphs().get(0);
|
||||
System.out.println("para=================>"+para);
|
||||
// System.out.println("para=================>"+para);
|
||||
for(int i = 0; i < doc.getSections().getCount(); i++) {
|
||||
Section section = doc.getSections().get(i);
|
||||
for (int j = 0; j < section.getParagraphs().getCount(); j++) {
|
||||
Paragraph paragraph = section.getParagraphs().get(j);
|
||||
System.out.println(j+"新方式内容"+paragraph.getText());
|
||||
// System.out.println(j+"新方式内容"+paragraph.getText());
|
||||
for (String pic: picNameList) {
|
||||
String replace = String.valueOf(paragraph.getText()).replace(",", "").replace(" ", "");
|
||||
if (replace.contains(picMap.get(pic).replace(",", "").replace(" ", ""))) {
|
||||
System.out.println("包含");
|
||||
// System.out.println("包含");
|
||||
String imgPath = IMG_DIR + randomFix +pic.replace("image", "");
|
||||
|
||||
File picture=new File(imgPath);
|
||||
@@ -1450,7 +1469,7 @@ public class TypesetController {
|
||||
}
|
||||
}
|
||||
picMap.put(imageName,lastParagraphText);
|
||||
System.out.println(pictureId +"\t|" + imageName + "\t|" + lastParagraphText);
|
||||
// System.out.println(pictureId +"\t|" + imageName + "\t|" + lastParagraphText);
|
||||
//获取word文本中所有的图片
|
||||
// List<XWPFPictureData> allPictures = xdoc.getAllPictures();
|
||||
//遍历照片
|
||||
@@ -1471,40 +1490,36 @@ public class TypesetController {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("picNameList===========>"+picNameList);
|
||||
System.out.println("picMap===========>"+picMap);
|
||||
// System.out.println("picNameList===========>"+picNameList);
|
||||
// System.out.println("picMap===========>"+picMap);
|
||||
//2.获取按模板新生成的文档添加图片
|
||||
File newFile = new File(newFileName);
|
||||
FileInputStream newFis = new FileInputStream(newFile);
|
||||
XWPFDocument newXdoc = new XWPFDocument(newFis);
|
||||
List<XWPFParagraph> paragraphs = newXdoc.getParagraphs();
|
||||
|
||||
|
||||
//其他方式
|
||||
Document doc = new Document();
|
||||
doc.loadFromFile(newFileName);
|
||||
Section sec = doc.getSections().get(0);
|
||||
System.out.println("sec=================>"+sec);
|
||||
// System.out.println("sec=================>"+sec);
|
||||
String text = doc.getText();
|
||||
System.out.println("text=================>"+text);
|
||||
// System.out.println("text=================>"+text);
|
||||
Paragraph para = sec.getParagraphs().get(0);
|
||||
System.out.println("para=================>"+para);
|
||||
// System.out.println("para=================>"+para);
|
||||
for(int i = 0; i < doc.getSections().getCount(); i++) {
|
||||
Section section = doc.getSections().get(i);
|
||||
for (int j = 0; j < section.getParagraphs().getCount(); j++) {
|
||||
Paragraph paragraph = section.getParagraphs().get(j);
|
||||
System.out.println(j+"新方式内容"+paragraph.getText());
|
||||
// System.out.println(j+"新方式内容"+paragraph.getText());
|
||||
for (String pic: picNameList) {
|
||||
String replace = String.valueOf(paragraph.getText()).replace(",", "").replace(" ", "");
|
||||
if (replace.contains(picMap.get(pic).replace(",", "").replace(" ", ""))) {
|
||||
System.out.println("包含");
|
||||
// System.out.println("包含");
|
||||
String imgPath = IMG_DIR + randomFix +pic.replace("image", "");
|
||||
|
||||
File picture=new File(imgPath);
|
||||
BufferedImage sourceImg= ImageIO.read(new FileInputStream(picture));
|
||||
int width = sourceImg.getWidth();
|
||||
sourceImg.getHeight();
|
||||
|
||||
System.out.println("图片长度"+width);
|
||||
//判断图片中是否包含 文字
|
||||
// String valCode = new OCRUtil().recognizeText(new File(imgPath));
|
||||
// System.out.println("valCode==============>"+valCode);
|
||||
@@ -1522,20 +1537,50 @@ public class TypesetController {
|
||||
// docPicture.setTextWrappingType(TextWrappingType.Both);
|
||||
// }else {
|
||||
//2.不包含 判断图片大小决定 图片为单栏还是双栏
|
||||
if (width <= 22000f){
|
||||
if (width <= 782f){
|
||||
//图片为小图 双栏
|
||||
DocPicture docPicture = paragraph.appendPicture(imgPath);
|
||||
docPicture.setWidth(220f);
|
||||
docPicture.setHeight(180f);
|
||||
docPicture.setWidth(250f);
|
||||
// docPicture.setHeight(216f);
|
||||
docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom);
|
||||
docPicture.setTextWrappingType(TextWrappingType.Both);
|
||||
float x = docPicture.getHorizontalPosition();
|
||||
float y = docPicture.getVerticalPosition();
|
||||
|
||||
//获取图片宽度、高度
|
||||
float width1 = docPicture.getWidth();
|
||||
float height = docPicture.getHeight();
|
||||
|
||||
//获取图片文字环绕
|
||||
String wrappingstyle = docPicture.getTextWrappingStyle().toString();//图片文字环绕方式
|
||||
String wrappingtype = docPicture.getTextWrappingType().toString();//环绕文字类型
|
||||
|
||||
System.out.println("坐标位置为: X =" + x + " Y=" + y
|
||||
+ "\n 图片宽:"+ width1 + " 图片高:" + height
|
||||
+ "\n 图片的文字环绕方式:" + wrappingstyle + " 环绕文字类型:" + wrappingtype);
|
||||
}else {
|
||||
//图片为大图 单栏
|
||||
DocPicture docPicture = paragraph.appendPicture(imgPath);
|
||||
docPicture.setWidth(500f);
|
||||
docPicture.setHeight(180f);
|
||||
docPicture.setWidth(495f);
|
||||
// docPicture.setHeight(150f);
|
||||
docPicture.setHorizontalPosition(0.0f);
|
||||
docPicture.setVerticalPosition(10.0f);
|
||||
docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom);
|
||||
docPicture.setTextWrappingType(TextWrappingType.Both);
|
||||
float x = docPicture.getHorizontalPosition();
|
||||
float y = docPicture.getVerticalPosition();
|
||||
|
||||
//获取图片宽度、高度
|
||||
float width1 = docPicture.getWidth();
|
||||
float height = docPicture.getHeight();
|
||||
|
||||
//获取图片文字环绕
|
||||
String wrappingstyle = docPicture.getTextWrappingStyle().toString();//图片文字环绕方式
|
||||
String wrappingtype = docPicture.getTextWrappingType().toString();//环绕文字类型
|
||||
|
||||
System.out.println("坐标位置为: X =" + x + " Y=" + y
|
||||
+ "\n 图片宽:"+ width1 + " 图片高:" + height
|
||||
+ "\n 图片的文字环绕方式:" + wrappingstyle + " 环绕文字类型:" + wrappingtype);
|
||||
}
|
||||
// }
|
||||
|
||||
@@ -1636,8 +1681,105 @@ public class TypesetController {
|
||||
System.out.println("输出完毕");
|
||||
// os.close();
|
||||
inputStream.close();
|
||||
newFis.close();
|
||||
filePath = IMG_DIR + randomFix + uuid+".docx";
|
||||
|
||||
filePath = randomFix + uuid+".docx";
|
||||
// //处理角标
|
||||
// File newFile = new File(filePath);
|
||||
// FileInputStream newFis = new FileInputStream(newFile);
|
||||
// XWPFDocument newXdoc = new XWPFDocument(newFis);
|
||||
// List<XWPFParagraph> paragraphs = newXdoc.getParagraphs();
|
||||
// for (XWPFParagraph paragraph: paragraphs
|
||||
// ) {
|
||||
// int runNumber = 0;
|
||||
// List<XWPFRun> runs = paragraph.getRuns();
|
||||
//
|
||||
// for (XWPFRun run : runs) {
|
||||
// String s = run.text();
|
||||
//// Pattern p = Pattern.compile("(?<=q).*?(?=q)");
|
||||
//// Matcher m = p.matcher(s);
|
||||
//// //找到角标文字
|
||||
//// while(m.find()) {
|
||||
// if (s.contains("<q>")){
|
||||
//// System.out.println("角标"+m.group());
|
||||
//// String group = m.group();
|
||||
// break;
|
||||
//
|
||||
//// char[] strArray = group.toCharArray();
|
||||
//// char[] runChars = s.toCharArray();
|
||||
//// for (char c : strArray) {
|
||||
////// String value = String.valueOf(c);
|
||||
////// if (s != null && s.contains(value)) { //if we have a run with an "a" in it, then
|
||||
////// char[] runChars = s.toCharArray();
|
||||
//// StringBuffer sb = new StringBuffer();
|
||||
//// for (int charNumber = 0; charNumber < runChars.length; charNumber++) { //go through all characters in that run
|
||||
//// if (runChars[charNumber] == c && String.valueOf(c) != null) { //if the charcter is an 'a' then
|
||||
////// run.setText(sb.toString(), 0); //set all characters, which are current buffered, as the text of the actual run
|
||||
////// r = paragraph.insertNewRun(++runNumber); //insert new run for the '@' as the replacement for the 'a'
|
||||
////// r.setText("@", 0);
|
||||
////// r.setColor("DC143C");
|
||||
////// r = paragraph.insertNewRun(++runNumber); //insert new run for the next characters
|
||||
//// run.setText(sb.toString(), 0); //set all characters, which are current buffered, as the text of the actual run
|
||||
//// run = paragraph.insertNewRun(++runNumber); //insert new run for the '@' as the replacement for the 'a'
|
||||
//// run.setText(String.valueOf(c), 0);
|
||||
//// run.setSubscript(VerticalAlign.SUPERSCRIPT);
|
||||
//// } else {
|
||||
//// sb.append(runChars[charNumber]); //buffer all characters which are not 'a's
|
||||
//// }
|
||||
//// }
|
||||
//// run.setText(sb.toString(), 0); //set all characters, which are current buffered, as the text of the actual run
|
||||
////// }
|
||||
////
|
||||
////
|
||||
//// }
|
||||
//// runNumber++;
|
||||
// }
|
||||
// }
|
||||
// XWPFRun run1 = paragraph.createRun();
|
||||
// run1.setText("112");
|
||||
// XWPFRun run2 = paragraph.createRun();
|
||||
// run2.setText("345");
|
||||
// run2.setSubscript(VerticalAlign.SUPERSCRIPT);
|
||||
//
|
||||
//// int runNumber = 0;
|
||||
//// while (runNumber < paragraph.getRuns().size()) { //go through all runs, we cannot use for each since we will possibly insert new runs
|
||||
////// XWPFRun r = paragraph.getRuns().get(runNumber);
|
||||
////// String runText = r.getText(0);
|
||||
//////
|
||||
//////
|
||||
////// Pattern p = Pattern.compile("/(?<=q).*?(?=q)/");
|
||||
////// Matcher m = p.matcher(runText);
|
||||
////// while(m.find()) {
|
||||
////// System.out.println("角标"+m.group(1));
|
||||
////// }
|
||||
////
|
||||
////
|
||||
////
|
||||
////
|
||||
////// if (runText != null && runText.contains("a")) { //if we have a run with an "a" in it, then
|
||||
////// char[] runChars = runText.toCharArray();
|
||||
////// StringBuffer sb = new StringBuffer();
|
||||
////// for (int charNumber = 0; charNumber < runChars.length; charNumber++) { //go through all characters in that run
|
||||
////// if (runChars[charNumber] == 'a') { //if the charcter is an 'a' then
|
||||
////// r.setText(sb.toString(), 0); //set all characters, which are current buffered, as the text of the actual run
|
||||
////// r = paragraph.insertNewRun(++runNumber); //insert new run for the '@' as the replacement for the 'a'
|
||||
////// r.setText("@", 0);
|
||||
////// r.setColor("DC143C");
|
||||
////// r = paragraph.insertNewRun(++runNumber); //insert new run for the next characters
|
||||
////// sb = new StringBuffer(); //empty buffer
|
||||
////// } else {
|
||||
////// sb.append(runChars[charNumber]); //buffer all characters which are not 'a's
|
||||
////// }
|
||||
////// }
|
||||
////// r.setText(sb.toString(), 0); //set all characters, which are current buffered, as the text of the actual run
|
||||
////// }
|
||||
////// runNumber++;
|
||||
//// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// newFis.close();
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user