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
19d1ba6c
Commit
19d1ba6c
authored
Oct 24, 2019
by
陈精华
Committed by
kl
Oct 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化:(内部)移除为pdf文档提供base64缩略图
parent
1060bdd0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
86 deletions
+0
-86
OnlinePreviewController.java
...ava/cn/keking/web/controller/OnlinePreviewController.java
+0
-86
No files found.
jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
View file @
19d1ba6c
...
@@ -8,10 +8,6 @@ import cn.keking.service.FilePreviewFactory;
...
@@ -8,10 +8,6 @@ import cn.keking.service.FilePreviewFactory;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.FileUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.rendering.ImageType
;
import
org.apache.pdfbox.rendering.PDFRenderer
;
import
org.apache.pdfbox.tools.imageio.ImageIOUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -24,11 +20,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
...
@@ -24,11 +20,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.io.*
;
import
java.net.*
;
import
java.net.*
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Base64
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -132,86 +126,6 @@ public class OnlinePreviewController {
...
@@ -132,86 +126,6 @@ public class OnlinePreviewController {
}
}
}
}
@RequestMapping
(
value
=
"/getPDFImage"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
String
getPDFImage
(
String
urlPath
,
Integer
dpi
,
Integer
page
)
{
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
urlPath
);
String
fileName
=
fileAttribute
.
getName
();
String
fullFileName
=
fileDir
+
fileName
;
String
result
=
""
;
InputStream
is
=
null
;
try
{
File
dirFile
=
new
File
(
fileDir
);
if
(!
dirFile
.
exists
())
{
dirFile
.
mkdirs
();
}
String
strUrl
=
urlPath
.
trim
();
URL
url
=
new
URL
(
new
URI
(
strUrl
).
toASCIIString
());
//打开请求连接
URLConnection
connection
=
url
.
openConnection
();
HttpURLConnection
httpURLConnection
=
(
HttpURLConnection
)
connection
;
httpURLConnection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"
);
is
=
httpURLConnection
.
getInputStream
();
FileOutputStream
os
=
new
FileOutputStream
(
fullFileName
);
byte
[]
buffer
=
new
byte
[
4
*
1024
];
int
read
;
while
((
read
=
is
.
read
(
buffer
))
>
0
)
{
os
.
write
(
buffer
,
0
,
read
);
}
os
.
close
();
try
{
String
imageFileSuffix
=
".jpg"
;
File
pdfFile
=
new
File
(
fullFileName
);
PDDocument
doc
=
PDDocument
.
load
(
pdfFile
);
int
pageCount
=
doc
.
getNumberOfPages
();
if
(
page
>=
pageCount
)
{
return
result
;
}
PDFRenderer
pdfRenderer
=
new
PDFRenderer
(
doc
);
int
index
=
fullFileName
.
lastIndexOf
(
"."
);
String
folder
=
fullFileName
.
substring
(
0
,
index
);
File
path
=
new
File
(
folder
);
if
(!
path
.
exists
())
{
path
.
mkdirs
();
}
String
imageFilePath
;
imageFilePath
=
folder
+
File
.
separator
+
page
+
imageFileSuffix
;
BufferedImage
image
=
pdfRenderer
.
renderImageWithDPI
(
page
,
dpi
,
ImageType
.
RGB
);
ImageIOUtil
.
writeImage
(
image
,
imageFilePath
,
dpi
);
File
imgFile
=
new
File
(
imageFilePath
);
FileInputStream
in
=
new
FileInputStream
(
imgFile
);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
byte
[]
b
=
new
byte
[
1024
];
int
i
=
0
;
while
((
i
=
in
.
read
(
b
))
!=
-
1
)
{
out
.
write
(
b
,
0
,
b
.
length
);
}
out
.
close
();
in
.
close
();
String
base64Image
=
"data:image/jpeg;base64,"
+
Base64
.
getEncoder
().
encodeToString
(
out
.
toByteArray
());
out
.
close
();
result
=
base64Image
;
doc
.
close
();
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"Convert pdf to jpg exception"
,
e
);
}
}
catch
(
IOException
|
URISyntaxException
e
)
{
LOGGER
.
error
(
"下载pdf文件失败"
,
e
);
}
finally
{
if
(
is
!=
null
)
{
IOUtils
.
closeQuietly
(
is
);
}
}
return
result
;
}
/**
/**
* 通过api接口入队
* 通过api接口入队
* @param url 请编码后在入队
* @param url 请编码后在入队
...
...
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