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
...
@@ -325,12 +325,13 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
public
String
convertPdf
(
String
modelName
,
Map
<
String
,
Object
>
dataMap
)
{
public
String
convertPdf
(
String
modelName
,
Map
<
String
,
Object
>
dataMap
)
{
String
targetPath
=
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/"
;
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"
);
File
pdfFile2
=
new
File
(
"TEMP/"
+
dataMap
.
get
(
"contextName"
)
+
"案卷目录"
+
"("
+
dataMap
.
get
(
"mj"
)
+
")"
+
".pdf"
);
try
{
try
{
InputStream
tempStream2
=
Files
.
newInputStream
(
wordFile
.
toPath
());
//
InputStream tempStream2 = Files.newInputStream(wordFile.toPath());
OutputStream
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
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
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
byteArrayInputStream
.
close
();
byteArrayInputStream
.
close
();
...
@@ -342,29 +343,25 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
...
@@ -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
)
{
public
String
fillWordAndConvertPdf
(
String
modelName
,
Map
<
String
,
Object
>
dataMap
,
String
pdfFileName
,
String
tempDir
)
{
String
targetPath
=
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/"
;
String
targetPath
=
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/"
;
File
wordFile
=
new
File
(
targetPath
+
modelName
);
String
tempFullPath
=
targetPath
+
modelName
;
File
pdfFile2
=
new
File
(
tempDir
+
File
.
separator
+
pdfFileName
+
".pdf"
);
File
pdfFile
=
new
File
(
tempDir
+
File
.
separator
+
pdfFileName
+
".pdf"
);
InputStream
tempStream
=
null
;
OutputStream
outputStream
=
null
;
ByteArrayInputStream
byteArrayInputStream
=
null
;
ByteArrayInputStream
byteArrayInputStream
=
null
;
try
{
try
(
OutputStream
outputStream
=
new
FileOutputStream
(
pdfFile
))
{
tempStream
=
Files
.
newInputStream
(
wordFile
.
toPath
());
byte
[]
wordBytes
=
WordUtils
.
fillWord
(
dataMap
,
tempFullPath
);
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
toPath
());
byteArrayInputStream
=
new
ByteArrayInputStream
(
wordBytes
);
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
tempStream
);
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
try
{
if
(
byteArrayInputStream
!=
null
)
{
byteArrayInputStream
.
close
();
try
{
temp
Stream
.
close
();
byteArrayInput
Stream
.
close
();
outputStream
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
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 {
...
@@ -308,11 +308,11 @@ public class WordUtils {
* 填充word模板,获取填充后的word文件流:
* 填充word模板,获取填充后的word文件流:
*
*
* @param datas: 填充数据
* @param datas: 填充数据
* @param
fileStream: 文件模板流 -- 可从OSS/FastDFS上获取流,直接传入;
* @param
tempPath: 模板地址
* @return
* @return
* @throws IOException
* @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
;
XWPFTemplate
template
=
null
;
ByteArrayOutputStream
wordOut
=
new
ByteArrayOutputStream
(
1024
);
ByteArrayOutputStream
wordOut
=
new
ByteArrayOutputStream
(
1024
);
try
{
try
{
...
@@ -324,7 +324,7 @@ public class WordUtils {
...
@@ -324,7 +324,7 @@ public class WordUtils {
.
build
();
.
build
();
//填充文本域:
//填充文本域:
template
=
XWPFTemplate
.
compile
(
fileStream
,
config
).
render
(
datas
);
template
=
XWPFTemplate
.
compile
(
tempPath
,
config
).
render
(
datas
);
template
.
write
(
wordOut
);
template
.
write
(
wordOut
);
}
catch
(
RenderException
ex
)
{
}
catch
(
RenderException
ex
)
{
log
.
error
(
"模板填充失败,请保证模板文本域与参数保持一致。错误信息::{}"
,
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