@@ -113,17 +113,32 @@ | |||
<artifactId>poi-ooxml-schemas</artifactId> | |||
<version>4.0.1</version> | |||
</dependency> | |||
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf --> | |||
<dependency> | |||
<groupId>com.lowagie</groupId> | |||
<artifactId>itext</artifactId> | |||
<version>2.1.7</version> | |||
<groupId>com.itextpdf</groupId> | |||
<artifactId>itextpdf</artifactId> | |||
<version>5.5.12</version> | |||
</dependency> | |||
<!-- https://mvnrepository.com/artifact/cn.lesper/iTextAsian --> | |||
<dependency> | |||
<groupId>com.lowagie</groupId> | |||
<artifactId>itext-rtf</artifactId> | |||
<version>2.1.7</version> | |||
<groupId>cn.lesper</groupId> | |||
<artifactId>iTextAsian</artifactId> | |||
<version>2.0</version> | |||
</dependency> | |||
<!-- <dependency> | |||
<groupId>com.lowagie</groupId> | |||
<artifactId>itext</artifactId> | |||
<version>2.1.7</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.lowagie</groupId> | |||
<artifactId>itext-rtf</artifactId> | |||
<version>2.1.7</version> | |||
</dependency>--> | |||
<!--阿里云视频点播--> | |||
<dependency> | |||
<groupId>com.aliyun</groupId> |
@@ -5,7 +5,8 @@ import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.lowagie.text.*; | |||
import com.itextpdf.text.*; | |||
import com.itextpdf.text.pdf.*; | |||
import com.tuoheng.admin.common.ServiceExceptionEnum; | |||
import com.tuoheng.admin.entity.domain.Question; | |||
import com.tuoheng.admin.entity.domain.Report; | |||
@@ -19,10 +20,7 @@ import com.tuoheng.admin.mapper.ThMissionMapper; | |||
import com.tuoheng.admin.service.IQuestionService; | |||
import com.tuoheng.admin.service.IReportService; | |||
import com.tuoheng.admin.service.IThInspectionService; | |||
import com.tuoheng.admin.utils.WeatherUtil; | |||
import com.tuoheng.admin.utils.WordUtilsOld; | |||
import com.tuoheng.common.common.BaseServiceImpl; | |||
import com.tuoheng.common.config.CommonConfig; | |||
import com.tuoheng.common.config.UploadFileConfig; | |||
import com.tuoheng.common.exception.ServiceException; | |||
import com.tuoheng.common.utils.DateUtils; | |||
@@ -39,9 +37,7 @@ import org.springframework.stereotype.Service; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.OutputStream; | |||
import java.io.*; | |||
import java.net.URLEncoder; | |||
import java.text.SimpleDateFormat; | |||
import java.util.*; | |||
@@ -223,38 +219,56 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
ReportInfoVO reportInfoVO = detail(reportId); | |||
//创建word | |||
String fileName = "汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc"; | |||
String fileName = "汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.pdf"; | |||
String filePath = UploadFileConfig.uploadFolder+"/doc/"+fileName; | |||
File fd = new File(UploadFileConfig.uploadFolder+"/doc"); | |||
File f = new File(filePath); | |||
if(!fd.exists()){ | |||
fd.mkdirs(); | |||
} | |||
WordUtilsOld wordUtils = new WordUtilsOld(); | |||
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
FileOutputStream outputStream=new FileOutputStream(f); | |||
if(f.exists()){ | |||
f.delete(); | |||
f.createNewFile(); | |||
} | |||
Document document = new Document(PageSize.A4, 71f, 71f, 72f, 72f); | |||
PdfWriter writer = PdfWriter.getInstance(document, outputStream); | |||
try { | |||
if(f.exists()){ | |||
f.delete(); | |||
f.createNewFile(); | |||
} | |||
log.info("开始编写word文件,文件为:{}",filePath); | |||
wordUtils.openDocument(filePath); | |||
wordUtils.getDocument().setPageSize(PageSize.A4); | |||
wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f); | |||
//标题 | |||
wordUtils.insertTitlePattern("汤山林场无人机巡检报告", WordUtilsOld.rtfGsBt1); | |||
wordUtils.insertContext("报告编号:"+reportInfoVO.getReportNo(),10, Font.NORMAL, Element.ALIGN_RIGHT,20,0,0); | |||
wordUtils.insertTitlePatternThird("一:林场信息", WordUtilsOld.rtfGsBt3); | |||
Table table = new Table(2);//生成一表格 | |||
table.setOffset(1f); | |||
document.open(); | |||
BaseFont bfChinese = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); | |||
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);// 中文、12、正常 | |||
Paragraph title = new Paragraph("汤山林场无人机巡检报告", getChineseFont()); | |||
Chapter chapter = new Chapter(title, 1); | |||
document.add(chapter); | |||
Paragraph context = new Paragraph("报告编号:"+reportInfoVO.getReportNo(), getChineseFont()); | |||
context.setFont(fontChinese); | |||
context.setAlignment(Element.ALIGN_RIGHT); | |||
document.add(context); | |||
Section section2 = getSection(chapter,"一:林场信息"); | |||
document.add(section2); | |||
PdfPTable table = new PdfPTable(2);//生成一表格 | |||
table.getDefaultCell().setBorderWidth(1f); | |||
int[] width = {1, 1}; | |||
table.setWidths(width);//设置系列所占比例 | |||
table.setWidth(100); | |||
table.setAutoFillEmptyCells(true); | |||
table.setAlignment(Element.ALIGN_LEFT);//居中显示 | |||
table.setTotalWidth(100); | |||
//table.setAutoFillEmptyCells(true); | |||
table.setHorizontalAlignment(Element.ALIGN_LEFT);//居中显示 | |||
for (int i = 0; i < 6; i++) { | |||
Cell cell = new Cell(); | |||
PdfPCell cell = new PdfPCell(); | |||
String str; | |||
cell.setVerticalAlignment(Element.ALIGN_RIGHT); | |||
cell.setHorizontalAlignment(Element.ALIGN_CENTER); | |||
@@ -278,25 +292,27 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
str = reportInfoVO.getMission().getMileage(); | |||
} | |||
Paragraph p = new Paragraph(str, font); | |||
cell.add(p); | |||
cell.addElement(p); | |||
table.addCell(cell); | |||
} | |||
wordUtils.getDocument().add(table); | |||
document.add(table); | |||
log.info("林场信息写入完成"); | |||
wordUtils.insertTitlePatternThird("二:巡检信息", WordUtilsOld.rtfGsBt3); | |||
Table table2 = new Table(2);//生成一表格 | |||
table2.setOffset(1f); | |||
Section section3 = getSection(chapter,"二:巡检信息"); | |||
document.add(section3); | |||
PdfPTable table2 = new PdfPTable(2);//生成一表格 | |||
table.getDefaultCell().setBorderWidth(1f); | |||
int[] width2 = {1, 1}; | |||
table2.setWidths(width2);//设置系列所占比例 | |||
table2.setWidth(100); | |||
table2.setAutoFillEmptyCells(true); | |||
table2.setAlignment(Element.ALIGN_CENTER);//居中显示 | |||
table2.setAlignment(Element.ALIGN_MIDDLE);//垂直居中显示 | |||
table2.setTotalWidth(100); | |||
//table2.setAutoFillEmptyCells(true); | |||
table2.setHorizontalAlignment(Element.ALIGN_CENTER);//居中显示 | |||
table2.setHorizontalAlignment(Element.ALIGN_MIDDLE);//垂直居中显示 | |||
for (int i = 0; i < 12; i++) { | |||
Cell cell = new Cell(); | |||
PdfPCell cell = new PdfPCell(); | |||
String str; | |||
cell.setVerticalAlignment(Element.ALIGN_LEFT); | |||
cell.setHorizontalAlignment(Element.ALIGN_CENTER); | |||
@@ -338,10 +354,10 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
} | |||
Paragraph p = new Paragraph(str, font); | |||
cell.add(p); | |||
cell.addElement(p); | |||
table2.addCell(cell); | |||
} | |||
wordUtils.getDocument().add(table2); | |||
document.add(table2); | |||
log.info("巡检信息写入完成"); | |||
List<QuestionTypeCountVO> questionTypeInfo = reportInfoVO.getQuestionTypeInfo(); | |||
@@ -351,19 +367,20 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
} | |||
if(questionTypeInfo.size()>0) { | |||
wordUtils.insertTitlePatternThird("三:巡检结果", WordUtilsOld.rtfGsBt3); | |||
Table table3 = new Table(2);//生成一表格 | |||
table3.setOffset(1f); | |||
Section section4 = getSection(chapter,"三:巡检结果"); | |||
document.add(section4); | |||
PdfPTable table3 = new PdfPTable(2);//生成一表格 | |||
table3.getDefaultCell().setBorderWidth(1f); | |||
int[] width3 = {1, 1}; | |||
table3.setWidths(width3);//设置系列所占比例 | |||
table3.setWidth(100); | |||
table3.setAutoFillEmptyCells(true); | |||
table3.setAlignment(Element.ALIGN_CENTER);//居中显示 | |||
table3.setAlignment(Element.ALIGN_MIDDLE);//垂直居中显示 | |||
table3.setTotalWidth(100); | |||
//table3.setAutoFillEmptyCells(true); | |||
table3.setHorizontalAlignment(Element.ALIGN_CENTER);//居中显示 | |||
table3.setHorizontalAlignment(Element.ALIGN_MIDDLE);//垂直居中显示 | |||
for (int i = 0; i < 10; i++) { | |||
Cell cell = new Cell(); | |||
PdfPCell cell = new PdfPCell(); | |||
String str; | |||
cell.setVerticalAlignment(Element.ALIGN_CENTER); | |||
cell.setHorizontalAlignment(Element.ALIGN_CENTER); | |||
@@ -417,29 +434,30 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
} | |||
Paragraph p = new Paragraph(str, font); | |||
cell.add(p); | |||
cell.addElement(p); | |||
table3.addCell(cell); | |||
} | |||
wordUtils.getDocument().add(table3); | |||
document.add(table3); | |||
} | |||
log.info("巡检结果写入完成"); | |||
if (reportInfoVO.getQuestionReportList().size() > 0) { | |||
wordUtils.insertTitlePatternThird("四:问题清单", WordUtilsOld.rtfGsBt3); | |||
Section section5 = getSection(chapter,"四:问题清单"); | |||
document.add(section5); | |||
log.info("报告标题四成功"); | |||
// wordUtils.getDocument().add(new Paragraph("")); | |||
for (int i = 0; i < reportInfoVO.getQuestionReportList().size(); i++) { | |||
Table table4 = new Table(2);//生成一表格 | |||
table4.setOffset(1f); | |||
PdfPTable table4 = new PdfPTable(2);//生成一表格 | |||
table.getDefaultCell().setBorderWidth(1f); | |||
int[] width4 = {1, 2}; | |||
table4.setWidths(width4);//设置系列所占比例 | |||
table4.setWidth(100); | |||
table4.setAutoFillEmptyCells(true); | |||
table4.setAlignment(Element.ALIGN_LEFT);//居中显示 | |||
table4.setAlignment(Element.ALIGN_MIDDLE);//垂直居中显示 | |||
table2.setTotalWidth(100); | |||
//table4.setAutoFillEmptyCells(true); | |||
table4.setHorizontalAlignment(Element.ALIGN_LEFT);//居中显示 | |||
table4.setHorizontalAlignment(Element.ALIGN_MIDDLE);//垂直居中显示 | |||
for (int j = 0; j < 7; j++) { | |||
Cell cell = new Cell(); | |||
PdfPCell cell = new PdfPCell(); | |||
//cell.setVerticalAlignment(Element.ALIGN_LEFT); | |||
//cell.setHorizontalAlignment(Element.ALIGN_CENTER); | |||
String str = ""; | |||
@@ -449,31 +467,31 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
if (j == 0) { | |||
font.setSize(12); | |||
str = " 问题" + (i + 1); | |||
cell.add(new Paragraph(str, font)); | |||
cell.addElement(new Paragraph(str, font)); | |||
cell.setColspan(2); | |||
font.setStyle(Font.BOLD); | |||
//cell.setVerticalAlignment(Element.ALIGN_LEFT); | |||
} else if (j == 1) { | |||
str = " 坐标"; | |||
cell.add(new Paragraph(str, font)); | |||
cell.addElement(new Paragraph(str, font)); | |||
} else if (j == 2) { | |||
str = reportInfoVO.getQuestionReportList().get(i).getLng() + "," + reportInfoVO.getQuestionReportList().get(i).getLat(); | |||
cell.add(new Paragraph(str, font)); | |||
cell.addElement(new Paragraph(str, font)); | |||
} else if (j == 3) { | |||
str = " 问题描述"; | |||
cell.add(new Paragraph(str, font)); | |||
cell.addElement(new Paragraph(str, font)); | |||
} else if (j == 4) { | |||
str = reportInfoVO.getQuestionReportList().get(i).getQuestionDesc(); | |||
cell.add(new Paragraph(str, font)); | |||
cell.addElement(new Paragraph(str, font)); | |||
} else if (j == 5) { | |||
str = " 问题图片"; | |||
cell.add(new Paragraph(str, font)); | |||
cell.addElement(new Paragraph(str, font)); | |||
} else{ | |||
//String url = CommonConfig.imageURL + reportInfoVO.getQuestionReportList().get(i).getFileMarkerUrl(); | |||
Image image = null; | |||
String url = reportInfoVO.getQuestionReportList().get(i).getFileMarkerUrl(); | |||
if (new UrlResource(url).exists()) { | |||
image = Image.getInstance("/data/java/tuoheng_lc/uploads/2022-08-18-17-30-54_frame-19128-19398_type-林斑_74d20d0c1ed811ed960b18c04d1a13ab-online-P20220818171703347-8c3e7407e6054db695aa0a07fe02bf0b_AI.jpg"); | |||
image = Image.getInstance(url); | |||
image.setAlignment(Image.ALIGN_CENTER); | |||
image.scalePercent(100); //依照比例缩放 | |||
image.setAbsolutePosition(0, 0); | |||
@@ -482,25 +500,26 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
log.error("图片不存在!" + url); | |||
} | |||
if (new UrlResource(url).exists()) { | |||
cell.add(image); | |||
cell.addElement(image); | |||
} else { | |||
cell.add(new Paragraph("")); | |||
cell.addElement(new Paragraph("")); | |||
} | |||
} | |||
table4.addCell(cell); | |||
} | |||
wordUtils.getDocument().add(table4); | |||
document.add(table4); | |||
} | |||
} | |||
wordUtils.closeDocument(); | |||
document.close(); | |||
writer.close(); | |||
log.info("问题清单写入完成"); | |||
//清空缓存 | |||
response.reset(); | |||
// 定义浏览器响应表头,并定义下载名 | |||
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8"); | |||
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.pdf", "UTF-8"); | |||
response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName); | |||
response.setCharacterEncoding("utf-8"); | |||
//定义下载的类型 | |||
@@ -527,10 +546,48 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp | |||
log.info("异常信息:{}",e.getMessage()); | |||
e.printStackTrace(); | |||
}finally { | |||
wordUtils.closeDocument(); | |||
document.close(); | |||
writer.close(); | |||
} | |||
} | |||
private Section getSection(Chapter chapter,String info) { | |||
Section section2 = chapter.addSection(new Paragraph(info, getChineseFont())); | |||
section2.setIndentation(30); | |||
section2.setIndentationLeft(5); | |||
section2.setBookmarkOpen(false); | |||
section2.setNumberStyle(Section.NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT); | |||
return section2; | |||
} | |||
public Font getChineseFont() { | |||
BaseFont bfChinese; | |||
Font fontChinese = null; | |||
try { | |||
bfChinese = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); | |||
// fontChinese = new Font(bfChinese, 12, Font.NORMAL); | |||
fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLUE); | |||
} catch (DocumentException e) { | |||
e.printStackTrace(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
return fontChinese; | |||
} | |||
/** |
@@ -0,0 +1,78 @@ | |||
package com.tuoheng.admin.utils; | |||
import com.itextpdf.text.Document; | |||
import com.itextpdf.text.PageSize; | |||
import com.itextpdf.text.Paragraph; | |||
import com.itextpdf.text.pdf.BaseFont; | |||
import java.awt.*; | |||
import java.io.IOException; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
public class PDFUtils { | |||
// private Document document = new Document(PageSize.A4, 71f, 71f, 72f, 72f); | |||
// | |||
// private Map<Integer,String> fontFamily = new HashMap<Integer,String>(); | |||
// | |||
// public PDFUtils(){ | |||
// document.newPage(); | |||
// //init font | |||
// if(getSystem()){ | |||
// fontFamily.put(1, "C:\\Windows\\Fonts\\simhei.ttf"); | |||
// fontFamily.put(2, "C:\\Windows\\Fonts\\STXINWEI.TTF"); | |||
// fontFamily.put(3, "C:\\Windows\\Fonts\\simsun.ttc,0"); | |||
// fontFamily.put(4, "C:\\Windows\\Fonts\\fangsong_GB2312.ttf"); | |||
// fontFamily.put(5, "C:\\Windows\\Fonts\\times.ttf"); | |||
// fontFamily.put(6, "C:\\Windows\\Fonts\\simfang.ttf"); | |||
// }else{ | |||
// fontFamily.put(1, "/usr/share/fonts/simhei.ttf"); | |||
// fontFamily.put(2, "/usr/share/fonts/STXINWEI.TTF"); | |||
// fontFamily.put(3, "/usr/share/fonts/windows/simsun.ttc,0"); | |||
// fontFamily.put(4, "/usr/share/fonts/fangsong_GB2312.ttf"); | |||
// fontFamily.put(5, "/usr/share/fonts/times.ttf"); | |||
// } | |||
// } | |||
/* public boolean getSystem(){ | |||
return System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOWS"); | |||
}*/ | |||
/* //第一级标题样式 | |||
public static RtfParagraphStyle rtfGsBt1 = RtfParagraphStyle.STYLE_HEADING_1; | |||
//第二级标题样式 | |||
public static RtfParagraphStyle rtfGsBt2 = RtfParagraphStyle.STYLE_HEADING_2; | |||
//第三级标题样式 | |||
public static RtfParagraphStyle rtfGsBt3 = RtfParagraphStyle.STYLE_HEADING_3; | |||
//第四级标题样式 | |||
public static RtfParagraphStyle rtfGsBt4 = RtfParagraphStyle.STYLE_HEADING_3;*/ | |||
// public void insertContext(String contextStr,int fontsize,int fontStyle,int elementAlign,float firstLineIndent,float before,float after) throws DocumentException, IOException { | |||
// // 正文字体风格 | |||
// BaseFont fontFamliy = BaseFont.createFont(fontFamily.get(3), "GBK", BaseFont.EMBEDDED); | |||
// Font contextFont = new Font("fontFamliy", fontsize, fontStyle); | |||
// Paragraph context = new Paragraph(contextStr); | |||
// //设置行距 | |||
// context.setLeading(3f); | |||
// // 正文格式左对齐 | |||
// context.setAlignment(elementAlign); | |||
// //context.setFont(contextFont); | |||
// // 离上一段落(标题)空的行数 | |||
// //context.setSpacingBefore(1); | |||
// // 设置第一行空的列数 | |||
// //context.setFirstLineIndent(20); | |||
// context.setFirstLineIndent(firstLineIndent); | |||
// context.setSpacingBefore(before); | |||
// context.setSpacingAfter(after); | |||
// document.add(context); | |||
// } | |||
} |
@@ -1,3 +1,4 @@ | |||
/* | |||
package com.tuoheng.admin.utils; | |||
import com.lowagie.text.*; | |||
@@ -14,25 +15,27 @@ import java.net.MalformedURLException; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
*/ | |||
/** | |||
* word帮助文件 | |||
*/ | |||
*//* | |||
public class WordUtilsOld { | |||
private Document document; | |||
private String test; | |||
private Map<Integer,String> fontFamily = new HashMap<Integer,String>(); | |||
public Document getDocument() { | |||
return document; | |||
} | |||
public void setDocument(Document document) { | |||
this.document = document; | |||
} | |||
public Document getDocument() { | |||
return document; | |||
} | |||
public void setDocument(Document document) { | |||
this.document = document; | |||
} | |||
public WordUtilsOld(){ | |||
this.document = new Document(PageSize.A4);//����ֽ�Ŵ�С | |||
this.document = new Document(PageSize.A4);//����ֽ�Ŵ�С | |||
document.newPage(); | |||
//init font | |||
if(getSystem()){ | |||
@@ -49,166 +52,185 @@ public class WordUtilsOld { | |||
fontFamily.put(4, "/usr/share/fonts/fangsong_GB2312.ttf"); | |||
fontFamily.put(5, "/usr/share/fonts/times.ttf"); | |||
} | |||
} | |||
/** 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中 | |||
} | |||
*/ | |||
/** 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中 | |||
* @param filePath 要操作的文档路径,若文档不存在会自动创建 | |||
* @throws com.lowagie.text.DocumentException | |||
* @throws IOException | |||
*/ | |||
public void openDocument(String filePath) throws DocumentException, | |||
IOException { | |||
// 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中 | |||
RtfWriter2.getInstance(this.document, new FileOutputStream(filePath)); | |||
this.document.open(); | |||
// 设置中文字体 | |||
/*this.bfChinese = BaseFont.createFont("STSongStd-Light", | |||
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);*/ | |||
*//* | |||
public void openDocument(String filePath) throws DocumentException, | |||
IOException { | |||
// 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中 | |||
RtfWriter2.getInstance(this.document, new FileOutputStream(filePath)); | |||
this.document.open(); | |||
// 设置中文字体 | |||
*/ | |||
/*this.bfChinese = BaseFont.createFont("STSongStd-Light", | |||
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);*//* | |||
} | |||
/** | |||
*/ | |||
/** | |||
* @param titleStr 标题 | |||
* @param fontsize 字体大小 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
* @param fontsize 字体大小 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
public void insertTitle(String titleStr,float fontsize,int fontStyle,int elementAlign,float before,float after,int fontFamliyType) throws Exception{ | |||
*//* | |||
public void insertTitle(String titleStr,float fontsize,int fontStyle,int elementAlign,float before,float after,int fontFamliyType) throws Exception{ | |||
BaseFont fontFamliy = BaseFont.createFont(fontFamily.get(3), "GBK", BaseFont.NOT_EMBEDDED); | |||
Font titleFont = new Font(fontFamliy,fontsize, fontStyle); | |||
Paragraph title = new Paragraph(titleStr); | |||
// 设置标题格式对齐方式 | |||
title.setAlignment(elementAlign); | |||
// 设置标题格式对齐方式 | |||
title.setAlignment(elementAlign); | |||
title.setFont(titleFont); | |||
title.setSpacingBefore(before); | |||
title.setSpacingAfter(after); | |||
this.document.add(title); | |||
} | |||
this.document.add(title); | |||
} | |||
/** | |||
*/ | |||
/** | |||
* 设置带有目录格式的标题(标题1格式) | |||
* | |||
* @param rtfParagraphStyle 标题1样式 | |||
* @param titleStr 标题 | |||
* @throws com.lowagie.text.DocumentException | |||
* @throws IOException | |||
*/ | |||
*//* | |||
public void insertTitlePattern(String titleStr, RtfParagraphStyle rtfParagraphStyle) throws DocumentException, IOException{ | |||
Paragraph title = new Paragraph(titleStr); | |||
title.setFont(rtfParagraphStyle); | |||
this.document.add(title); | |||
} | |||
} | |||
/** | |||
*/ | |||
/** | |||
* 设置带有目录格式的标题(标题2格式) | |||
* @param titleStr 标题 | |||
* @param rtfParagraphStyle 标题2样式 | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
*//* | |||
public void insertTitlePatternSecond(String titleStr,RtfParagraphStyle rtfParagraphStyle) throws DocumentException{ | |||
Paragraph title = new Paragraph(titleStr); | |||
// 设置标题格式对齐方式 | |||
// 设置标题格式对齐方式 | |||
title.setFont(rtfParagraphStyle); | |||
this.document.add(title); | |||
} | |||
/** | |||
} | |||
*/ | |||
/** | |||
* 设置带有目录格式的标题(标题3格式) | |||
* @param titleStr 标题 | |||
* @param rtfParagraphStyle 标题3样式 | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
*//* | |||
public void insertTitlePatternThird(String titleStr,RtfParagraphStyle rtfParagraphStyle) throws DocumentException{ | |||
Paragraph title = new Paragraph(titleStr); | |||
// 设置标题格式对齐方式 | |||
// 设置标题格式对齐方式 | |||
title.setFont(rtfParagraphStyle); | |||
this.document.add(title); | |||
} | |||
/** | |||
* @param tableName 标题 | |||
* @param fontsize 字体大小 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
} | |||
*/ | |||
/** | |||
* @param tableName 标题 | |||
* @param fontsize 字体大小 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
public void insertTableName(String tableName,int fontsize,int fontStyle,int elementAlign) throws DocumentException{ | |||
Font titleFont = new Font(); | |||
*//* | |||
public void insertTableName(String tableName,int fontsize,int fontStyle,int elementAlign) throws DocumentException{ | |||
Font titleFont = new Font(); | |||
titleFont.setColor(102, 102, 153); | |||
Paragraph title = new Paragraph(tableName); | |||
// 设置标题格式对齐方式 | |||
title.setAlignment(elementAlign); | |||
title.setFont(titleFont); | |||
this.document.add(title); | |||
} | |||
/** | |||
* @param contextStr 内容 | |||
* @param fontsize 字体大小 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
Paragraph title = new Paragraph(tableName); | |||
// 设置标题格式对齐方式 | |||
title.setAlignment(elementAlign); | |||
title.setFont(titleFont); | |||
this.document.add(title); | |||
} | |||
*/ | |||
/** | |||
* @param contextStr 内容 | |||
* @param fontsize 字体大小 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
* @throws com.lowagie.text.DocumentException | |||
* @throws IOException | |||
*/ | |||
public void insertContext(String contextStr,int fontsize,int fontStyle,int elementAlign,float firstLineIndent,float before,float after) throws DocumentException, IOException{ | |||
// 正文字体风格 | |||
*//* | |||
public void insertContext(String contextStr,int fontsize,int fontStyle,int elementAlign,float firstLineIndent,float before,float after) throws DocumentException, IOException{ | |||
// 正文字体风格 | |||
BaseFont fontFamliy = BaseFont.createFont(fontFamily.get(3), "GBK", BaseFont.EMBEDDED); | |||
Font contextFont = new Font(fontFamliy, fontsize, fontStyle); | |||
Paragraph context = new Paragraph(contextStr); | |||
//设置行距 | |||
Font contextFont = new Font(fontFamliy, fontsize, fontStyle); | |||
Paragraph context = new Paragraph(contextStr); | |||
//设置行距 | |||
context.setLeading(3f); | |||
// 正文格式左对齐 | |||
// 正文格式左对齐 | |||
context.setAlignment(elementAlign); | |||
context.setFont(contextFont); | |||
// 离上一段落(标题)空的行数 | |||
context.setFont(contextFont); | |||
// 离上一段落(标题)空的行数 | |||
//context.setSpacingBefore(1); | |||
// 设置第一行空的列数 | |||
//context.setFirstLineIndent(20); | |||
// 设置第一行空的列数 | |||
//context.setFirstLineIndent(20); | |||
context.setFirstLineIndent(firstLineIndent); | |||
context.setSpacingBefore(before); | |||
context.setSpacingAfter(after); | |||
document.add(context); | |||
document.add(context); | |||
} | |||
/** | |||
*/ | |||
/** | |||
* 插入正文里的注释 | |||
* @param contextStr 内容 | |||
* @param contextStr 内容 | |||
* @param fontsize 字体大小 5号 10.5 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
* @param fontStyle 字体样式 | |||
* @param elementAlign 对齐方式 | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
public void insertContextNote(String contextStr,int fontsize,int fontStyle,int elementAlign,float firstLineIndent,float before,float after) throws Exception{ | |||
*//* | |||
public void insertContextNote(String contextStr,int fontsize,int fontStyle,int elementAlign,float firstLineIndent,float before,float after) throws Exception{ | |||
BaseFont fontFamliy = BaseFont.createFont(fontFamily.get(3), "GBK", BaseFont.EMBEDDED); | |||
Font contextFont = new Font(fontFamliy, 10.5f, fontStyle); | |||
Paragraph context = new Paragraph(contextStr); | |||
Font contextFont = new Font(fontFamliy, 10.5f, fontStyle); | |||
Paragraph context = new Paragraph(contextStr); | |||
context.setLeading(3f); | |||
context.setAlignment(elementAlign); | |||
context.setFont(contextFont); | |||
context.setFont(contextFont); | |||
context.setFirstLineIndent(firstLineIndent); | |||
context.setSpacingBefore(before); | |||
context.setSpacingAfter(after); | |||
document.add(context); | |||
document.add(context); | |||
} | |||
public void insertContext(Paragraph context) throws Exception{ | |||
public void insertContext(Paragraph context) throws Exception{ | |||
BaseFont fontFamliy = BaseFont.createFont(fontFamily.get(3), "GBK", BaseFont.EMBEDDED); | |||
Font contextFont = new Font(fontFamliy,12); | |||
Font contextFont = new Font(fontFamliy,12); | |||
context.setFont(contextFont); | |||
document.add(context); | |||
document.add(context); | |||
} | |||
/** | |||
*/ | |||
/** | |||
* @param imgUrl 图片路径 | |||
* @param imageAlign 显示位置 | |||
* @param height 显示高度 | |||
@@ -220,28 +242,31 @@ public class WordUtilsOld { | |||
* @throws MalformedURLException | |||
* @throws IOException | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
public void insertImg(String imgUrl,int imageAlign,int height,int weight,int percent,int heightPercent,int weightPercent,int rotation) throws MalformedURLException, IOException, DocumentException{ | |||
// 添加图片 | |||
Image img = Image.getInstance(imgUrl); | |||
if(img==null) | |||
return; | |||
img.setAbsolutePosition(0, 0); | |||
img.setAlignment(imageAlign); | |||
*//* | |||
public void insertImg(String imgUrl,int imageAlign,int height,int weight,int percent,int heightPercent,int weightPercent,int rotation) throws MalformedURLException, IOException, DocumentException{ | |||
// 添加图片 | |||
Image img = Image.getInstance(imgUrl); | |||
if(img==null) | |||
return; | |||
img.setAbsolutePosition(0, 0); | |||
img.setAlignment(imageAlign); | |||
img.scaleAbsolute(height, weight); | |||
img.scaleAbsolute(1000, 1000); | |||
img.scalePercent(percent); | |||
img.scalePercent(heightPercent, weightPercent); | |||
img.setRotation(rotation); | |||
img.scalePercent(heightPercent, weightPercent); | |||
img.setRotation(rotation); | |||
document.add(img); | |||
} | |||
/** | |||
*/ | |||
/** | |||
* 添加简单表格 | |||
* @param column 表格列数(必须) | |||
* @param row 表格行数 | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
*//* | |||
public void insertSimpleTable(int column,int row) throws DocumentException { | |||
Table table=new Table(column);//列数必须设置,而行数则可以按照个人要求来决定是否需要设置 | |||
table.setAlignment(Element.ALIGN_CENTER);// 居中显示 | |||
@@ -257,46 +282,50 @@ public class WordUtilsOld { | |||
} | |||
document.add(table); | |||
} | |||
public void insertContext2(String contextStr,int fontsize,int fontStyle,int elementAlign,float firstLineIndent,float hangju,float before,float after,int fontFamliyType) throws DocumentException, IOException{ | |||
BaseFont fontFamliy = BaseFont.createFont(fontFamily.get(fontFamliyType), "GBK", BaseFont.EMBEDDED); | |||
Font contextFont = new Font(fontFamliy, fontsize, fontStyle); | |||
Paragraph context = new Paragraph(contextStr); | |||
//设置行距 | |||
Font contextFont = new Font(fontFamliy, fontsize, fontStyle); | |||
Paragraph context = new Paragraph(contextStr); | |||
//设置行距 | |||
context.setLeading(hangju); | |||
// 正文格式左对齐 | |||
// 正文格式左对齐 | |||
context.setAlignment(elementAlign); | |||
context.setFont(contextFont); | |||
context.setFont(contextFont); | |||
context.setFirstLineIndent(firstLineIndent); | |||
context.setSpacingBefore(before); | |||
context.setSpacingAfter(after); | |||
document.add(context); | |||
document.add(context); | |||
} | |||
/** | |||
*/ | |||
/** | |||
* 新增 | |||
* hxl 2019-3-29 | |||
* 设置字体 | |||
* @param fontFamliyType | |||
* @return | |||
* @throws Exception | |||
*/ | |||
*//* | |||
public BaseFont setFont(int fontFamliyType) throws Exception{ | |||
BaseFont fontFamliy = BaseFont.createFont(fontFamily.get(3), "GBK", BaseFont.NOT_EMBEDDED); | |||
return fontFamliy; | |||
} | |||
/** | |||
*/ | |||
/** | |||
* 在操作完成后必须关闭document,否则即使生成了word文档,打开也会发生错误 | |||
* @throws com.lowagie.text.DocumentException | |||
*/ | |||
public void closeDocument() throws DocumentException{ | |||
this.document.close(); | |||
} | |||
*//* | |||
public void closeDocument() throws DocumentException{ | |||
this.document.close(); | |||
} | |||
//判断操作系统类型 | |||
public boolean getSystem(){ | |||
if(System.getProperties().getProperty("os.name").toUpperCase().indexOf("WINDOWS")!=-1){ | |||
@@ -360,3 +389,4 @@ public class WordUtilsOld { | |||
rtfGsBt4.setFontName("FangSong_GB2312"); | |||
} | |||
} | |||
*/ |