Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pdf2pptx
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guanzixin
pdf2pptx
Commits
c1cde5f9
Commit
c1cde5f9
authored
Jul 09, 2019
by
tannongchun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改内容
parent
5815c54d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
2 deletions
+100
-2
src/main/java/com/jtyjy/pdf2pptx/application/AppListener.java
+33
-0
src/main/java/com/jtyjy/pdf2pptx/converter/Pdf2Pptx.java
+62
-1
src/main/java/com/jtyjy/pdf2pptx/support/Constant.java
+1
-1
src/main/resources/application.yml
+4
-0
No files found.
src/main/java/com/jtyjy/pdf2pptx/application/AppListener.java
0 → 100644
View file @
c1cde5f9
package
com
.
jtyjy
.
pdf2pptx
.
application
;
import
com.jtyjy.pdf2pptx.service.ConverterService
;
import
com.jtyjy.pdf2pptx.support.Constant
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.Calendar
;
import
java.util.Date
;
@Component
public
class
AppListener
implements
ApplicationListener
<
ContextRefreshedEvent
>
{
@Value
(
"${file.path}"
)
private
String
filepath
;
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
AppListener
.
class
);
@Autowired
private
ConverterService
converterService
;
@Override
public
void
onApplicationEvent
(
ContextRefreshedEvent
contextRefreshedEvent
)
{
System
.
err
.
println
(
"正在处理 "
+
filepath
);
System
.
err
.
println
(
"处理开始 "
+
new
Date
());
converterService
.
converterPdf2Pptx
(
filepath
);
System
.
err
.
println
(
"处理完成 "
+
new
Date
());
}
}
src/main/java/com/jtyjy/pdf2pptx/converter/Pdf2Pptx.java
View file @
c1cde5f9
...
...
@@ -23,9 +23,17 @@ public class Pdf2Pptx {
public
static
void
main
(
String
[]
args
)
{
//读取指定文件夹下所有文件并转换为图片
// conver(Constant.SOURCE_PATH);
//删除所有生成的图片文件
List
<
String
>
allDirPathName
=
new
ArrayList
<>();
FileUtil
.
getAllDirPathNameRe
(
Constant
.
SOURCE_PATH
,
allDirPathName
);
for
(
String
delFolder
:
allDirPathName
)
{
if
(
delFolder
(
delFolder
))
{
logger
.
info
(
"删除文件夹:{}及其文件成功"
,
delFolder
);
}
}
}
public
void
converte
(
String
path
){
public
void
converte
(
String
path
)
{
conver
(
path
);
}
...
...
@@ -80,6 +88,59 @@ public class Pdf2Pptx {
}
}
//删除所有生成的图片文件
for
(
String
dirPathName
:
allDirPathName
)
{
if
(
delFolder
(
dirPathName
))
{
logger
.
info
(
"删除文件夹:{}及其文件成功"
,
dirPathName
);
}
}
}
//删除指定文件夹下所有文件
public
static
boolean
delAllFile
(
String
path
)
{
boolean
flag
=
false
;
File
file
=
new
File
(
path
);
if
(!
file
.
exists
())
{
return
flag
;
}
if
(!
file
.
isDirectory
())
{
return
flag
;
}
String
[]
tempList
=
file
.
list
();
File
temp
=
null
;
for
(
int
i
=
0
;
i
<
tempList
.
length
;
i
++)
{
if
(
path
.
endsWith
(
File
.
separator
))
{
temp
=
new
File
(
path
+
tempList
[
i
]);
}
else
{
temp
=
new
File
(
path
+
File
.
separator
+
tempList
[
i
]);
}
if
(
temp
.
isFile
())
{
temp
.
delete
();
}
if
(
temp
.
isDirectory
())
{
delAllFile
(
path
+
"/"
+
tempList
[
i
]);
//先删除文件夹里面的文件
delFolder
(
path
+
"/"
+
tempList
[
i
]);
//再删除空文件夹
flag
=
true
;
}
}
return
flag
;
}
//删除文件夹
//param folderPath 文件夹完整绝对路径
public
static
boolean
delFolder
(
String
folderPath
)
{
try
{
delAllFile
(
folderPath
);
//删除完里面所有内容
String
filePath
=
folderPath
;
filePath
=
filePath
.
toString
();
java
.
io
.
File
myFilePath
=
new
java
.
io
.
File
(
filePath
);
return
myFilePath
.
delete
();
//删除空文件夹
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
}
src/main/java/com/jtyjy/pdf2pptx/support/Constant.java
View file @
c1cde5f9
...
...
@@ -6,6 +6,6 @@ public class Constant {
* 待读取文件根目录
*/
// public static String SOURCE_PATH = "F:\\测试文档";
public
static
String
SOURCE_PATH
=
"
F:\\高二
"
;
public
static
String
SOURCE_PATH
=
"
D:\\document
"
;
}
src/main/resources/application.yml
View file @
c1cde5f9
# 注意斜杠
file
:
path
:
D:\\document
\ No newline at end of file
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