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
c1a7cd8c
Commit
c1a7cd8c
authored
Nov 21, 2019
by
陈精华
Committed by
kl
Nov 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新功能点,加入CAD图纸.dwg文件预览
parent
5888c56f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
159 additions
and
2 deletions
+159
-2
aspose-cad-19.9.jar
jodconverter-web/lib/aspose-cad-19.9.jar
+0
-0
pom.xml
jodconverter-web/pom.xml
+7
-0
FileType.java
jodconverter-web/src/main/java/cn/keking/model/FileType.java
+2
-1
CadFilePreviewImpl.java
.../main/java/cn/keking/service/impl/CadFilePreviewImpl.java
+96
-0
CadToPdf.java
jodconverter-web/src/main/java/cn/keking/utils/CadToPdf.java
+50
-0
FileUtils.java
...onverter-web/src/main/java/cn/keking/utils/FileUtils.java
+4
-1
No files found.
jodconverter-web/lib/aspose-cad-19.9.jar
0 → 100644
View file @
c1a7cd8c
File added
jodconverter-web/pom.xml
View file @
c1a7cd8c
...
@@ -183,6 +183,13 @@
...
@@ -183,6 +183,13 @@
<artifactId>
pdfbox-tools
</artifactId>
<artifactId>
pdfbox-tools
</artifactId>
<version>
2.0.15
</version>
<version>
2.0.15
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.aspose
</groupId>
<artifactId>
aspose-cad
</artifactId>
<version>
19.9
</version>
<scope>
system
</scope>
<systemPath>
${basedir}/lib/aspose-cad-19.9.jar
</systemPath>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<resources>
<resources>
...
...
jodconverter-web/src/main/java/cn/keking/model/FileType.java
View file @
c1a7cd8c
...
@@ -11,7 +11,8 @@ public enum FileType {
...
@@ -11,7 +11,8 @@ public enum FileType {
simText
(
"simTextFilePreviewImpl"
),
simText
(
"simTextFilePreviewImpl"
),
pdf
(
"pdfFilePreviewImpl"
),
pdf
(
"pdfFilePreviewImpl"
),
other
(
"otherFilePreviewImpl"
),
other
(
"otherFilePreviewImpl"
),
media
(
"mediaFilePreviewImpl"
);
media
(
"mediaFilePreviewImpl"
),
cad
(
"cadFilePreviewImpl"
);
private
String
instanceName
;
private
String
instanceName
;
FileType
(
String
instanceName
){
FileType
(
String
instanceName
){
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java
0 → 100644
View file @
c1a7cd8c
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.CadToPdf
;
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
org.springframework.util.StringUtils
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
java.util.List
;
/**
* @author chenjh
* @since 2019/11/21 14:28
*/
@Service
public
class
CadFilePreviewImpl
implements
FilePreview
{
private
String
fileDir
=
ConfigConstants
.
getFileDir
();
@Autowired
private
FileUtils
fileUtils
;
@Autowired
private
DownloadUtils
downloadUtils
;
@Autowired
private
CadToPdf
cadToPdf
;
@Autowired
private
PdfUtils
pdfUtils
;
public
static
final
String
OFFICE_PREVIEW_TYPE_PDF
=
"pdf"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_ALLIMAGES
=
"allImages"
;
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
// 预览Type,参数传了就取参数的,没传取系统默认
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
baseUrl
=
(
String
)
RequestContextHolder
.
currentRequestAttributes
().
getAttribute
(
"baseUrl"
,
0
);
String
suffix
=
fileAttribute
.
getSuffix
();
String
fileName
=
fileAttribute
.
getName
();
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
outFilePath
=
fileDir
+
pdfName
;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
String
filePath
=
fileDir
+
fileName
;
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
null
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
}
filePath
=
response
.
getContent
();
if
(
StringUtils
.
hasText
(
outFilePath
))
{
boolean
convertResult
=
cadToPdf
.
cadToPdf
(
filePath
,
outFilePath
);
if
(!
convertResult
)
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
"cad文件转换异常,请联系管理员"
);
return
"fileNotSupported"
;
}
if
(
ConfigConstants
.
isCacheEnabled
())
{
// 加入缓存
fileUtils
.
addConvertedFile
(
pdfName
,
fileUtils
.
getRelativePath
(
outFilePath
));
}
}
}
if
(
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
}
model
.
addAttribute
(
"imgurls"
,
imageUrls
);
model
.
addAttribute
(
"currentUrl"
,
imageUrls
.
get
(
0
));
if
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
))
{
return
"officePicture"
;
}
else
{
return
"picture"
;
}
}
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
return
"pdf"
;
}
}
jodconverter-web/src/main/java/cn/keking/utils/CadToPdf.java
0 → 100644
View file @
c1a7cd8c
package
cn
.
keking
.
utils
;
import
com.aspose.cad.Color
;
import
com.aspose.cad.fileformats.cad.CadDrawTypeMode
;
import
com.aspose.cad.imageoptions.CadRasterizationOptions
;
import
com.aspose.cad.imageoptions.PdfOptions
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.OutputStream
;
/**
* @author chenjhc
* @since 2019/11/21 14:34
*/
@Component
public
class
CadToPdf
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CadToPdf
.
class
);
public
boolean
cadToPdf
(
String
inputFilePath
,
String
outputFilePath
)
{
com
.
aspose
.
cad
.
Image
cadImage
=
com
.
aspose
.
cad
.
Image
.
load
(
inputFilePath
);
CadRasterizationOptions
cadRasterizationOptions
=
new
CadRasterizationOptions
();
cadRasterizationOptions
.
setLayouts
(
new
String
[]{
"Model"
});
cadRasterizationOptions
.
setNoScaling
(
true
);
cadRasterizationOptions
.
setBackgroundColor
(
Color
.
getWhite
());
cadRasterizationOptions
.
setPageWidth
(
cadImage
.
getWidth
());
cadRasterizationOptions
.
setPageHeight
(
cadImage
.
getHeight
());
cadRasterizationOptions
.
setPdfProductLocation
(
"center"
);
cadRasterizationOptions
.
setAutomaticLayoutsScaling
(
true
);
cadRasterizationOptions
.
setDrawType
(
CadDrawTypeMode
.
UseObjectColor
);
PdfOptions
pdfOptions
=
new
PdfOptions
();
pdfOptions
.
setVectorRasterizationOptions
(
cadRasterizationOptions
);
File
outputFile
=
new
File
(
outputFilePath
);
OutputStream
stream
=
null
;
try
{
stream
=
new
FileOutputStream
(
outputFile
);
cadImage
.
save
(
stream
,
pdfOptions
);
cadImage
.
close
();
return
true
;
}
catch
(
FileNotFoundException
e
)
{
logger
.
error
(
"PDFFileNotFoundException"
,
e
);
return
false
;
}
}
}
jodconverter-web/src/main/java/cn/keking/utils/FileUtils.java
View file @
c1a7cd8c
...
@@ -91,9 +91,12 @@ public class FileUtils {
...
@@ -91,9 +91,12 @@ public class FileUtils {
if
(
Arrays
.
asList
(
media
).
contains
(
fileType
.
toLowerCase
()))
{
if
(
Arrays
.
asList
(
media
).
contains
(
fileType
.
toLowerCase
()))
{
return
FileType
.
media
;
return
FileType
.
media
;
}
}
if
(
"pdf"
.
equalsIgnoreCase
(
fileType
))
{
if
(
"pdf"
.
equalsIgnoreCase
(
fileType
))
{
return
FileType
.
pdf
;
return
FileType
.
pdf
;
}
}
if
(
"dwg"
.
equalsIgnoreCase
(
fileType
))
{
return
FileType
.
cad
;
}
return
FileType
.
other
;
return
FileType
.
other
;
}
}
/**
/**
...
...
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