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
jenkins
slm-fileview
Commits
29726c11
Commit
29726c11
authored
Apr 28, 2019
by
陈精华
Committed by
kl
Apr 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDF预览也支持图片模式和查看大图
parent
336a18ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
OfficeFilePreviewImpl.java
...in/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
+1
-0
PdfFilePreviewImpl.java
.../main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
+54
-0
No files found.
jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
View file @
29726c11
...
...
@@ -60,6 +60,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
if
(!
new
File
(
filePath
).
exists
())
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
decodedUrl
,
suffix
,
null
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
}
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
View file @
29726c11
package
cn
.
keking
.
service
.
impl
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.ReturnResponse
;
import
cn.keking.service.FilePreview
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.PdfUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
java.io.File
;
import
java.util.List
;
/**
* Created by kl on 2018/1/17.
* Content :处理pdf文件
...
...
@@ -11,9 +21,53 @@ import org.springframework.ui.Model;
@Service
public
class
PdfFilePreviewImpl
implements
FilePreview
{
@Autowired
FileUtils
fileUtils
;
@Autowired
PdfUtils
pdfUtils
;
@Autowired
DownloadUtils
downloadUtils
;
String
fileDir
=
ConfigConstants
.
getFileDir
();
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
)
{
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
url
);
String
decodedUrl
=
fileAttribute
.
getDecodedUrl
();
String
suffix
=
fileAttribute
.
getSuffix
();
String
fileName
=
fileAttribute
.
getName
();
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
""
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
model
.
addAttribute
(
"pdfUrl"
,
url
);
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
outFilePath
=
fileDir
+
pdfName
;
if
(
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
))
{
//当文件不存在时,就去下载
if
(!
new
File
(
outFilePath
).
exists
())
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
decodedUrl
,
suffix
,
fileName
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
}
outFilePath
=
response
.
getContent
();
}
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
url
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"pdf转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
}
model
.
addAttribute
(
"imgurls"
,
imageUrls
);
model
.
addAttribute
(
"currentUrl"
,
imageUrls
.
get
(
0
));
if
(
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
))
{
return
"officePicture"
;
}
else
{
return
"picture"
;
}
}
return
"pdf"
;
}
}
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