Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
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
梁杰芳
slm-fileview
Commits
bf0e9ba0
Commit
bf0e9ba0
authored
Nov 29, 2021
by
liangjf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 转换格式异常后缓存处理
parent
1191cfc6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
8 deletions
+19
-8
AbstractConversionTask.java
...org/artofsolving/jodconverter/AbstractConversionTask.java
+1
-0
OfficeToPdfService.java
...r/src/main/java/cn/keking/service/OfficeToPdfService.java
+15
-6
OfficeFilePreviewImpl.java
...in/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
+3
-2
No files found.
office-plugin/src/main/java/org/artofsolving/jodconverter/AbstractConversionTask.java
View file @
bf0e9ba0
...
...
@@ -116,6 +116,7 @@ public abstract class AbstractConversionTask implements OfficeTask {
try
{
cast
(
XStorable
.
class
,
document
).
storeToURL
(
toUrl
(
outputFile
),
toUnoProperties
(
storeProperties
));
}
catch
(
ErrorCodeIOException
errorCodeIOException
)
{
throw
new
OfficeException
(
"could not store document: "
+
outputFile
.
getName
()
+
"; errorCode: "
+
errorCodeIOException
.
ErrCode
,
errorCodeIOException
);
}
catch
(
IOException
ioException
)
{
throw
new
OfficeException
(
"could not store document: "
+
outputFile
.
getName
(),
ioException
);
...
...
server/src/main/java/cn/keking/service/OfficeToPdfService.java
View file @
bf0e9ba0
package
cn
.
keking
.
service
;
import
org.artofsolving.jodconverter.OfficeDocumentConverter
;
import
org.artofsolving.jodconverter.office.OfficeException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
...
...
@@ -20,22 +21,29 @@ public class OfficeToPdfService {
this
.
officePluginManager
=
officePluginManager
;
}
public
void
openOfficeToPDF
(
String
inputFilePath
,
String
outputFilePath
)
{
office2pdf
(
inputFilePath
,
outputFilePath
);
public
boolean
openOfficeToPDF
(
String
inputFilePath
,
String
outputFilePath
)
{
return
office2pdf
(
inputFilePath
,
outputFilePath
);
}
public
static
void
converterFile
(
File
inputFile
,
String
outputFilePath_end
,
OfficeDocumentConverter
converter
)
{
public
static
boolean
converterFile
(
File
inputFile
,
String
outputFilePath_end
,
OfficeDocumentConverter
converter
)
{
File
outputFile
=
new
File
(
outputFilePath_end
);
// 假如目标路径不存在,则新建该路径
if
(!
outputFile
.
getParentFile
().
exists
()
&&
!
outputFile
.
getParentFile
().
mkdirs
())
{
logger
.
error
(
"创建目录【{}】失败,请检查目录权限!"
,
outputFilePath_end
);
}
try
{
converter
.
convert
(
inputFile
,
outputFile
);
}
catch
(
OfficeException
e
)
{
logger
.
error
(
"{}"
,
e
);
return
false
;
}
return
true
;
}
public
void
office2pdf
(
String
inputFilePath
,
String
outputFilePath
)
{
public
boolean
office2pdf
(
String
inputFilePath
,
String
outputFilePath
)
{
OfficeDocumentConverter
converter
=
officePluginManager
.
getDocumentConverter
();
if
(
null
!=
inputFilePath
)
{
File
inputFile
=
new
File
(
inputFilePath
);
...
...
@@ -45,15 +53,16 @@ public class OfficeToPdfService {
String
outputFilePath_end
=
getOutputFilePath
(
inputFilePath
);
if
(
inputFile
.
exists
())
{
// 找不到源文件, 则返回
converterFile
(
inputFile
,
outputFilePath_end
,
converter
);
return
converterFile
(
inputFile
,
outputFilePath_end
,
converter
);
}
}
else
{
if
(
inputFile
.
exists
())
{
// 找不到源文件, 则返回
converterFile
(
inputFile
,
outputFilePath
,
converter
);
return
converterFile
(
inputFile
,
outputFilePath
,
converter
);
}
}
}
return
false
;
}
public
static
String
getOutputFilePath
(
String
inputFilePath
)
{
...
...
server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
View file @
bf0e9ba0
...
...
@@ -54,12 +54,13 @@ public class OfficeFilePreviewImpl implements FilePreview {
}
filePath
=
response
.
getContent
();
if
(
StringUtils
.
hasText
(
outFilePath
))
{
officeToPdfService
.
openOfficeToPDF
(
filePath
,
outFilePath
);
// 这里将office文件转成pdf了,转换时出错还继续加缓存,加个布尔值限制缓存行为
boolean
cast
=
officeToPdfService
.
openOfficeToPDF
(
filePath
,
outFilePath
);
if
(
isHtml
)
{
// 对转换后的文件进行操作(改变编码方式)
fileHandlerService
.
doActionConvertedFile
(
outFilePath
);
}
if
(
ConfigConstants
.
isCacheEnabled
())
{
if
(
cast
&&
ConfigConstants
.
isCacheEnabled
())
{
// 加入缓存
fileHandlerService
.
addConvertedFile
(
pdfName
,
fileHandlerService
.
getRelativePath
(
outFilePath
));
}
...
...
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