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
e9650d7c
Commit
e9650d7c
authored
Jul 13, 2019
by
guanguan1009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
825483d3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
22 deletions
+62
-22
pom.xml
+4
-0
src/main/java/com/jtyjy/pdf2pptx/application/AppListener.java
+8
-2
src/main/java/com/jtyjy/pdf2pptx/application/ShutdownContext.java
+18
-0
src/main/java/com/jtyjy/pdf2pptx/converter/Pdf2Png.java
+1
-0
src/main/java/com/jtyjy/pdf2pptx/converter/Pdf2Pptx.java
+18
-17
src/main/java/com/jtyjy/pdf2pptx/support/Constant.java
+1
-1
src/main/resources/application.yml
+12
-2
No files found.
pom.xml
View file @
e9650d7c
...
...
@@ -62,6 +62,10 @@
<artifactId>
fastjson
</artifactId>
<version>
1.2.54
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/jtyjy/pdf2pptx/application/AppListener.java
View file @
e9650d7c
...
...
@@ -7,10 +7,13 @@ 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.ConfigurableApplicationContext
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.stereotype.Component
;
import
javax.swing.*
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.util.Calendar
;
import
java.util.Date
;
...
...
@@ -23,11 +26,14 @@ public class AppListener implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
private
ConverterService
converterService
;
@Override
public
void
onApplicationEvent
(
ContextRefreshedEvent
contextRefreshedEvent
)
{
System
.
err
.
println
(
"正在处理 "
+
filepath
);
System
.
err
.
println
(
"处理开始 "
+
new
Date
());
System
.
err
.
println
(
"处理开始 "
+
LocalDateTime
.
now
());
converterService
.
converterPdf2Pptx
(
filepath
);
System
.
err
.
println
(
"处理完成 "
+
new
Date
());
System
.
err
.
println
(
"处理完成 "
+
LocalDateTime
.
now
());
JOptionPane
.
showMessageDialog
(
new
JFrame
().
getContentPane
(),
"文件转换完成!"
,
"提示"
,
JOptionPane
.
INFORMATION_MESSAGE
);
}
}
src/main/java/com/jtyjy/pdf2pptx/application/ShutdownContext.java
0 → 100644
View file @
e9650d7c
package
com
.
jtyjy
.
pdf2pptx
.
application
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Component
;
@Component
public
class
ShutdownContext
{
@Autowired
private
ApplicationContext
appContext
;
public
void
initiateShutdown
(
int
returnCode
){
SpringApplication
.
exit
(
appContext
,
()
->
returnCode
);
}
}
src/main/java/com/jtyjy/pdf2pptx/converter/Pdf2Png.java
View file @
e9650d7c
...
...
@@ -115,6 +115,7 @@ public class Pdf2Png {
ImageIO
.
write
(
image
,
"png"
,
dstFile
);
}
logger
.
info
(
"PDF文档:{} 转PNG图片成功!{}页-{}页"
,
PdfFilePath
,
startPage
+
1
,
endPage
);
System
.
err
.
println
(
"PDF文档:["
+
PdfFilePath
+
"] 转PNG图片成功!["
+
startPage
+
1
+
"]页-["
+
endPage
+
"]页"
);
}
private
static
boolean
createDirectory
(
String
folder
)
{
...
...
src/main/java/com/jtyjy/pdf2pptx/converter/Pdf2Pptx.java
View file @
e9650d7c
package
com
.
jtyjy
.
pdf2pptx
.
converter
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jtyjy.pdf2pptx.application.ShutdownContext
;
import
com.jtyjy.pdf2pptx.support.Constant
;
import
com.jtyjy.pdf2pptx.support.FileUtil
;
import
com.jtyjy.pdf2pptx.support.PdfTask
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.stereotype.Component
;
import
javax.swing.*
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -33,11 +38,16 @@ public class Pdf2Pptx {
private
static
ExecutorService
executorService
;
@Autowired
private
ShutdownContext
shutdownContext
;
public
void
converte
(
String
path
)
{
conver
(
path
);
conver
(
path
,
null
);
// shutdownContext.initiateShutdown(0);
}
private
static
void
conver
(
String
path
)
{
private
static
void
conver
(
String
path
,
ConfigurableApplicationContext
context
)
{
System
.
setProperty
(
"java.awt.headless"
,
"false"
);
//读取指定文件夹下所有文件并转换为图片
long
startTime
=
System
.
currentTimeMillis
();
List
<
String
>
allFilePathName
=
new
ArrayList
<>();
...
...
@@ -53,13 +63,13 @@ public class Pdf2Pptx {
logger
.
info
(
"转换pdf:{} 为图片开始"
,
file
.
getAbsolutePath
());
long
begin
=
System
.
currentTimeMillis
();
executorService
=
Executors
.
newFixedThreadPool
(
6
);
Pdf2Png
.
pdf2Image
(
file
.
getAbsolutePath
(),
file
.
getParent
(),
300
,
executorService
);
Pdf2Png
.
pdf2Image
(
file
.
getAbsolutePath
(),
file
.
getParent
(),
300
,
executorService
);
long
end
=
System
.
currentTimeMillis
();
logger
.
info
(
"转换pdf:{} 为图片完成,耗时{}ms"
,
file
.
getAbsolutePath
(),
end
-
begin
);
while
(
exeFlag
)
{
if
(((
ThreadPoolExecutor
)
executorService
).
getActiveCount
()
==
0
)
{
executorService
.
shutdown
();
exeFlag
=
false
;
exeFlag
=
false
;
System
.
out
.
println
(
"转换图片已经完成"
);
}
}
...
...
@@ -71,13 +81,13 @@ public class Pdf2Pptx {
}
}
else
{
logger
.
info
(
"文件:{} 已经转换"
,
file
.
getAbsolutePath
());
System
.
err
.
println
(
"文件:["
+
file
.
getAbsolutePath
()
+
"] 已经转换"
);
}
}
}
//将图片插入PPT
List
<
String
>
allDirPathName
=
new
ArrayList
<>();
FileUtil
.
getAllDirPathNameRe
(
path
,
allDirPathName
);
...
...
@@ -101,7 +111,7 @@ public class Pdf2Pptx {
while
(
exeFlag
)
{
if
(((
ThreadPoolExecutor
)
executorService
).
getActiveCount
()
==
0
)
{
executorService
.
shutdown
();
exeFlag
=
false
;
exeFlag
=
false
;
System
.
out
.
println
(
"转换ppt已经完成"
);
logger
.
info
(
"转换所有ppt已经完成"
);
}
...
...
@@ -114,7 +124,6 @@ public class Pdf2Pptx {
logger
.
info
(
"删除文件夹:{}及其文件成功"
,
dirPathName
);
}
}
}
/**
...
...
@@ -145,16 +154,8 @@ 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
dirPathName
:
allDirPathName
)
{
if
(
dirPathName
.
endsWith
(
"_图片"
)
&&
FileUtil
.
delFolder
(
dirPathName
))
{
logger
.
info
(
"删除文件夹:{}及其文件成功"
,
dirPathName
);
}
}
int
processors
=
Runtime
.
getRuntime
().
availableProcessors
();
System
.
out
.
println
(
processors
);
}
}
src/main/java/com/jtyjy/pdf2pptx/support/Constant.java
View file @
e9650d7c
...
...
@@ -5,7 +5,7 @@ public class Constant {
/**
* 待读取文件根目录
*/
public
static
String
SOURCE_PATH
=
"F:\\
测试文档\\高二
"
;
public
static
String
SOURCE_PATH
=
"F:\\
document\\高二\\难卷
"
;
// public static String SOURCE_PATH = "F:\\高二";
}
src/main/resources/application.yml
View file @
e9650d7c
# 注意斜杠
file
:
path
:
D:\\document
\ No newline at end of file
path
:
D:\\document
#启用shutdown
management
:
endpoint
:
shutdown
:
enabled
:
true
endpoints
:
web
:
exposure
:
include
:
shutdown,info,health
base-path
:
/manage
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