Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dcs-doc-expand
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
INET-TWO
server
dcs-doc-expand
Commits
4a2e0097
Commit
4a2e0097
authored
Nov 21, 2024
by
wangqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
卷内目录生成pdf文件后,将临时目录及文件删除
parent
a2a8e48a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
22 deletions
+19
-22
ExtFilesServiceImpl.java
...t/dcs/document/core/service/impl/ExtFilesServiceImpl.java
+16
-19
WordUtils.java
.../main/java/com/inet/dcs/document/core/util/WordUtils.java
+3
-3
No files found.
inet-doc-expand-core/src/main/java/com/inet/dcs/document/core/service/impl/ExtFilesServiceImpl.java
View file @
4a2e0097
...
...
@@ -325,12 +325,13 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
public
String
convertPdf
(
String
modelName
,
Map
<
String
,
Object
>
dataMap
)
{
String
targetPath
=
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/"
;
File
wordFile
=
new
File
(
targetPath
+
modelName
);
//File wordFile = new File(targetPath + modelName);
String
tempFullPath
=
targetPath
+
modelName
;
File
pdfFile2
=
new
File
(
"TEMP/"
+
dataMap
.
get
(
"contextName"
)
+
"案卷目录"
+
"("
+
dataMap
.
get
(
"mj"
)
+
")"
+
".pdf"
);
try
{
InputStream
tempStream2
=
Files
.
newInputStream
(
wordFile
.
toPath
());
//
InputStream tempStream2 = Files.newInputStream(wordFile.toPath());
OutputStream
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
toPath
());
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
temp
Stream2
);
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
temp
FullPath
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
byteArrayInputStream
.
close
();
...
...
@@ -342,29 +343,25 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
public
String
fillWordAndConvertPdf
(
String
modelName
,
Map
<
String
,
Object
>
dataMap
,
String
pdfFileName
,
String
tempDir
)
{
String
targetPath
=
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/"
;
File
wordFile
=
new
File
(
targetPath
+
modelName
);
File
pdfFile2
=
new
File
(
tempDir
+
File
.
separator
+
pdfFileName
+
".pdf"
);
InputStream
tempStream
=
null
;
OutputStream
outputStream
=
null
;
String
tempFullPath
=
targetPath
+
modelName
;
File
pdfFile
=
new
File
(
tempDir
+
File
.
separator
+
pdfFileName
+
".pdf"
);
ByteArrayInputStream
byteArrayInputStream
=
null
;
try
{
tempStream
=
Files
.
newInputStream
(
wordFile
.
toPath
());
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
toPath
());
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
tempStream
);
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
try
(
OutputStream
outputStream
=
new
FileOutputStream
(
pdfFile
))
{
byte
[]
wordBytes
=
WordUtils
.
fillWord
(
dataMap
,
tempFullPath
);
byteArrayInputStream
=
new
ByteArrayInputStream
(
wordBytes
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
byteArrayInputStream
.
close
();
temp
Stream
.
close
();
outputStream
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
if
(
byteArrayInputStream
!=
null
)
{
try
{
byteArrayInput
Stream
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
return
pdfFile
2
.
getAbsolutePath
();
return
pdfFile
.
getAbsolutePath
();
}
...
...
inet-doc-expand-core/src/main/java/com/inet/dcs/document/core/util/WordUtils.java
View file @
4a2e0097
...
...
@@ -308,11 +308,11 @@ public class WordUtils {
* 填充word模板,获取填充后的word文件流:
*
* @param datas: 填充数据
* @param
fileStream: 文件模板流 -- 可从OSS/FastDFS上获取流,直接传入;
* @param
tempPath: 模板地址
* @return
* @throws IOException
*/
public
static
byte
[]
fillWord
(
Map
<
String
,
Object
>
datas
,
InputStream
fileStream
)
throws
IOException
{
public
static
byte
[]
fillWord
(
Map
<
String
,
Object
>
datas
,
String
tempPath
)
throws
IOException
{
XWPFTemplate
template
=
null
;
ByteArrayOutputStream
wordOut
=
new
ByteArrayOutputStream
(
1024
);
try
{
...
...
@@ -324,7 +324,7 @@ public class WordUtils {
.
build
();
//填充文本域:
template
=
XWPFTemplate
.
compile
(
fileStream
,
config
).
render
(
datas
);
template
=
XWPFTemplate
.
compile
(
tempPath
,
config
).
render
(
datas
);
template
.
write
(
wordOut
);
}
catch
(
RenderException
ex
)
{
log
.
error
(
"模板填充失败,请保证模板文本域与参数保持一致。错误信息::{}"
,
ex
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment