Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
warehouse
概览
Overview
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
苗卫卫
warehouse
Commits
b13670dc
提交
b13670dc
authored
1 年前
作者:
苗卫卫
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
aspost.words包引入
父级
d06d8778
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
119 行增加
和
119 行删除
+119
-119
pom.xml
+5
-5
src/main/java/com/boco/nbd/wios/flow/service/impl/OrderServiceImpl.java
+1
-1
src/main/java/com/boco/nbd/wios/flow/util/PdfUtil.java
+113
-113
没有找到文件。
pom.xml
查看文件 @
b13670dc
...
@@ -111,11 +111,11 @@
...
@@ -111,11 +111,11 @@
<version>
3.4.1
</version>
<version>
3.4.1
</version>
</dependency>
</dependency>
<!-- <dependency>--
>
<dependency
>
<!-- <groupId>com.aspose</groupId>--
>
<groupId>
com.aspose
</groupId
>
<!-- <artifactId>aspose-words</artifactId>--
>
<artifactId>
aspose-words
</artifactId
>
<!-- <version>15.8.0</version>--
>
<version>
15.8.0
</version
>
<!-- </dependency>--
>
</dependency
>
</dependencies>
</dependencies>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/boco/nbd/wios/flow/service/impl/OrderServiceImpl.java
查看文件 @
b13670dc
...
@@ -1581,7 +1581,7 @@ public class OrderServiceImpl extends BaseDaoService3<OrderPO, FlowOrderMapper>
...
@@ -1581,7 +1581,7 @@ public class OrderServiceImpl extends BaseDaoService3<OrderPO, FlowOrderMapper>
indexOne
++;
indexOne
++;
}
}
blockPairBo
.
setExperiences
(
data
);
blockPairBo
.
setExperiences
(
data
);
//
pdfUtil.getWord(path, blockPairBo, fileName, response);
pdfUtil
.
getWord
(
path
,
blockPairBo
,
fileName
,
response
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/boco/nbd/wios/flow/util/PdfUtil.java
查看文件 @
b13670dc
...
@@ -3,7 +3,7 @@ package com.boco.nbd.wios.flow.util;
...
@@ -3,7 +3,7 @@ package com.boco.nbd.wios.flow.util;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
//
import com.aspose.words.*;
import
com.aspose.words.*
;
import
com.boco.nbd.cams.core.constant.CamsConstant
;
import
com.boco.nbd.cams.core.constant.CamsConstant
;
import
com.boco.nbd.wios.flow.entity.pdf.BlockPairBo
;
import
com.boco.nbd.wios.flow.entity.pdf.BlockPairBo
;
import
com.boco.nbd.wios.flow.entity.pdf.SurveyDataBo
;
import
com.boco.nbd.wios.flow.entity.pdf.SurveyDataBo
;
...
@@ -40,20 +40,20 @@ public class PdfUtil {
...
@@ -40,20 +40,20 @@ public class PdfUtil {
judgment
=
0
;
judgment
=
0
;
}
}
//
private static boolean getLicense() {
private
static
boolean
getLicense
()
{
//
boolean result = false;
boolean
result
=
false
;
//
//
try {
try
{
//
InputStream is = PdfUtil.class.getClassLoader().getResourceAsStream("License.xml");
InputStream
is
=
PdfUtil
.
class
.
getClassLoader
().
getResourceAsStream
(
"License.xml"
);
//
License aposeLic = new License();
License
aposeLic
=
new
License
();
//
aposeLic.setLicense(is);
aposeLic
.
setLicense
(
is
);
//
result = true;
result
=
true
;
//
} catch (Exception var3) {
}
catch
(
Exception
var3
)
{
//
var3.printStackTrace();
var3
.
printStackTrace
();
//
}
}
//
//
return result;
return
result
;
//
}
}
/**
/**
* 根据模板生成word
* 根据模板生成word
...
@@ -61,59 +61,59 @@ public class PdfUtil {
...
@@ -61,59 +61,59 @@ public class PdfUtil {
* @param path 模板的路径
* @param path 模板的路径
* @param fileName 生成word文件的文件名
* @param fileName 生成word文件的文件名
*/
*/
//
public void getWord(String path, BlockPairBo blockPairBo, String fileName, HttpServletResponse response) throws Exception {
public
void
getWord
(
String
path
,
BlockPairBo
blockPairBo
,
String
fileName
,
HttpServletResponse
response
)
throws
Exception
{
//
ClassPathResource resource = new ClassPathResource(path);
ClassPathResource
resource
=
new
ClassPathResource
(
path
);
//
InputStream is = resource.getInputStream();
InputStream
is
=
resource
.
getInputStream
();
//
String saveRoute = path.substring(0, path.lastIndexOf("/"));
String
saveRoute
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
"/"
));
//
XWPFTemplate xwpfTemplate = XWPFTemplate.compile(is);
XWPFTemplate
xwpfTemplate
=
XWPFTemplate
.
compile
(
is
);
//
ByteArrayOutputStream output = new ByteArrayOutputStream();
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
//
if (judgment == 0) {
if
(
judgment
==
0
)
{
//
fileName = java.net.URLDecoder.decode(fileName, CamsConstant.UTF_8);
fileName
=
java
.
net
.
URLDecoder
.
decode
(
fileName
,
CamsConstant
.
UTF_8
);
//
xwpfTemplate.render(blockPairBo).write(output);
xwpfTemplate
.
render
(
blockPairBo
).
write
(
output
);
//
String pdf = fileName.substring(0, fileName.lastIndexOf(".")) + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".pdf";
String
pdf
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
))
+
DateUtil
.
format
(
new
Date
(),
DatePattern
.
PURE_DATETIME_PATTERN
)
+
".pdf"
;
//
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
ByteArrayInputStream
input
=
new
ByteArrayInputStream
(
output
.
toByteArray
());
//
doc2pdf(input, saveRoute + "/" + pdf);
doc2pdf
(
input
,
saveRoute
+
"/"
+
pdf
);
//
File file = new File(saveRoute + "/" + pdf);
File
file
=
new
File
(
saveRoute
+
"/"
+
pdf
);
//
//判断文件大小,并压缩
//判断文件大小,并压缩
//
if (file.length() > WiosConstant.FILE_SIZE) {
if
(
file
.
length
()
>
WiosConstant
.
FILE_SIZE
)
{
//
file.delete();
file
.
delete
();
//
for (SurveyDataBo bo : blockPairBo.getExperiences()) {
for
(
SurveyDataBo
bo
:
blockPairBo
.
getExperiences
())
{
//
compressPictures(bo);
compressPictures
(
bo
);
//
}
}
//
getWord(path, blockPairBo, fileName, response);
getWord
(
path
,
blockPairBo
,
fileName
,
response
);
//
return;
return
;
//
}
}
//
try {
try
{
//
log.info("========================{}下载开始========================", pdf);
log
.
info
(
"========================{}下载开始========================"
,
pdf
);
//
is = new BufferedInputStream(new FileInputStream(saveRoute + "/" + pdf));
is
=
new
BufferedInputStream
(
new
FileInputStream
(
saveRoute
+
"/"
+
pdf
));
//
byte[] buffer = new byte[is.available()];
byte
[]
buffer
=
new
byte
[
is
.
available
()];
//
is.read(buffer);
is
.
read
(
buffer
);
//
response.reset();
response
.
reset
();
//
// 设置response的Header
// 设置response的Header
//
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), CamsConstant.UTF_8));
response
.
addHeader
(
"Content-Disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
file
.
getName
(),
CamsConstant
.
UTF_8
));
//
response.addHeader("Content-Length", "" + file.length());
response
.
addHeader
(
"Content-Length"
,
""
+
file
.
length
());
//
response.setContentType("application/octet-stream");
response
.
setContentType
(
"application/octet-stream"
);
//
response.setCharacterEncoding("utf-8");
response
.
setCharacterEncoding
(
"utf-8"
);
//
OutputStream os = new BufferedOutputStream(response.getOutputStream());
OutputStream
os
=
new
BufferedOutputStream
(
response
.
getOutputStream
());
//
os.write(buffer);
os
.
write
(
buffer
);
//
os.flush();
os
.
flush
();
//
log.info("========================{}下载结束========================", pdf);
log
.
info
(
"========================{}下载结束========================"
,
pdf
);
//
//删除缓存文件
//删除缓存文件
//
file.delete();
file
.
delete
();
//
} catch (IOException ex) {
}
catch
(
IOException
ex
)
{
//
log.error(pdf + "下载异常:", ex);
log
.
error
(
pdf
+
"下载异常:"
,
ex
);
//
ex.printStackTrace();
ex
.
printStackTrace
();
//
}
}
//
} else {
}
else
{
//
fileName = java.net.URLDecoder.decode(fileName, CamsConstant.UTF_8);
fileName
=
java
.
net
.
URLDecoder
.
decode
(
fileName
,
CamsConstant
.
UTF_8
);
//
output = new ByteArrayOutputStream();
output
=
new
ByteArrayOutputStream
();
//
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileName
);
//
xwpfTemplate.write(output);
xwpfTemplate
.
write
(
output
);
//
judgment = 0;
judgment
=
0
;
//
}
}
//
this.close(output);
this
.
close
(
output
);
//
this.close(is);
this
.
close
(
is
);
//
}
}
/**
/**
* 关闭输入流
* 关闭输入流
...
@@ -169,49 +169,49 @@ public class PdfUtil {
...
@@ -169,49 +169,49 @@ public class PdfUtil {
* @param wordPath word 的路径 word 的路径
* @param wordPath word 的路径 word 的路径
* @param pdfPath pdf 的路径
* @param pdfPath pdf 的路径
*/
*/
//
public static void doc2pdf(String wordPath, String pdfPath) {
public
static
void
doc2pdf
(
String
wordPath
,
String
pdfPath
)
{
//
if (getLicense()) {
if
(
getLicense
())
{
//
try {
try
{
//
long old = System.currentTimeMillis();
long
old
=
System
.
currentTimeMillis
();
//
File file = new File(pdfPath);
File
file
=
new
File
(
pdfPath
);
//
FileOutputStream os = new FileOutputStream(file);
FileOutputStream
os
=
new
FileOutputStream
(
file
);
//
Document doc = new Document(wordPath);
Document
doc
=
new
Document
(
wordPath
);
//
//
doc.save(os, 40);
doc
.
save
(
os
,
40
);
//
long now = System.currentTimeMillis();
long
now
=
System
.
currentTimeMillis
();
//
os.close();
os
.
close
();
//
log.info("共耗时:" + (double) (now - old) / 1000.0D + "秒");
log
.
info
(
"共耗时:"
+
(
double
)
(
now
-
old
)
/
1000.0
D
+
"秒"
);
//
} catch (Exception var9) {
}
catch
(
Exception
var9
)
{
//
var9.printStackTrace();
var9
.
printStackTrace
();
//
}
}
//
//
}
}
//
}
}
//
public static void doc2pdf(InputStream is, String pdfPath) {
public
static
void
doc2pdf
(
InputStream
is
,
String
pdfPath
)
{
//
if (getLicense()) {
if
(
getLicense
())
{
//
try {
try
{
//
long old = System.currentTimeMillis();
long
old
=
System
.
currentTimeMillis
();
//
File file = new File(pdfPath);
File
file
=
new
File
(
pdfPath
);
//
if (!file.getParentFile().exists()) {
if
(!
file
.
getParentFile
().
exists
())
{
//
file.getParentFile().mkdirs();
file
.
getParentFile
().
mkdirs
();
//
}
}
//
FileOutputStream os = new FileOutputStream(pdfPath);
FileOutputStream
os
=
new
FileOutputStream
(
pdfPath
);
//
Document doc = new Document(is);
Document
doc
=
new
Document
(
is
);
//
PdfSaveOptions options = new PdfSaveOptions();
PdfSaveOptions
options
=
new
PdfSaveOptions
();
//
// 文字和图像压缩
// 文字和图像压缩
//
options.setExportDocumentStructure(true);
options
.
setExportDocumentStructure
(
true
);
//
options.setTextCompression(PdfTextCompression.FLATE);
options
.
setTextCompression
(
PdfTextCompression
.
FLATE
);
//
options.setImageCompression(PdfImageCompression.AUTO);
options
.
setImageCompression
(
PdfImageCompression
.
AUTO
);
//
// 接收修订
// 接收修订
//
doc.acceptAllRevisions();
doc
.
acceptAllRevisions
();
//
doc.save(os, options);
doc
.
save
(
os
,
options
);
//
long now = System.currentTimeMillis();
long
now
=
System
.
currentTimeMillis
();
//
os.close();
os
.
close
();
//
log.info("共耗时:" + (double) (now - old) / 1000.0D + "秒");
log
.
info
(
"共耗时:"
+
(
double
)
(
now
-
old
)
/
1000.0
D
+
"秒"
);
//
} catch (Exception var9) {
}
catch
(
Exception
var9
)
{
//
var9.printStackTrace();
var9
.
printStackTrace
();
//
}
}
//
}
}
//
}
}
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论