Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
ppttoimages
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
夏彬
ppttoimages
Commits
e447c353
Commit
e447c353
authored
Nov 30, 2016
by
夏彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first commit
parents
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
259 additions
and
0 deletions
+259
-0
.gitignore
.gitignore
+10
-0
pom.xml
pom.xml
+81
-0
PptToImages.java
src/main/java/cc/pp/PptToImages.java
+168
-0
.gitignore
src/test/java/.gitignore
+0
-0
No files found.
.gitignore
0 → 100644
View file @
e447c353
*~
.*.swp
.classpath
.project
.settings/
target/
logs/
.idea/
*.iml
distribution.sh
pom.xml
0 → 100644
View file @
e447c353
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cc.pp
</groupId>
<artifactId>
ppttoimages
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<repositories>
<repository>
<id>
ppcc-public
</id>
<name>
Nexus Release Repository
</name>
<url>
http://gitlab.fingerage.com:3305/nexus/content/groups/public/
</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.15
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
3.15
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-scratchpad
</artifactId>
<version>
3.15
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml-schemas
</artifactId>
<version>
3.15
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-shade-plugin
</artifactId>
<version>
1.4
</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>
package
</phase>
<goals>
<goal>
shade
</goal>
</goals>
<configuration>
<filters>
<filter>
<!-- Do not copy the signatures in the META-INF folder.
Otherwise, this might cause SecurityExceptions when using the JAR. -->
<artifact>
*:*
</artifact>
<excludes>
<exclude>
META-INF/*.SF
</exclude>
<exclude>
META-INF/*.DSA
</exclude>
<exclude>
META-INF/*.RSA
</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"
>
<mainClass>
cc.pp.PptToImages
</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>
false
</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
src/main/java/cc/pp/PptToImages.java
0 → 100644
View file @
e447c353
package
cc
.
pp
;
import
org.apache.poi.hslf.usermodel.HSLFSlide
;
import
org.apache.poi.hslf.usermodel.HSLFSlideShow
;
import
org.apache.poi.xslf.usermodel.XMLSlideShow
;
import
org.apache.poi.xslf.usermodel.XSLFSlide
;
import
java.awt.*
;
import
java.awt.geom.Rectangle2D
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
/**
* Created by xiabin on 2016/11/30.
*/
/**
* main
*/
public
class
PptToImages
{
/**
* @param args
*/
public
static
void
main
(
String
[]
args
)
{
// 读入PPT文件
if
(
args
.
length
!=
1
)
{
System
.
out
.
println
(
"Usage:"
);
System
.
out
.
println
(
" command file"
);
return
;
}
System
.
out
.
println
(
"文件名:"
+
args
[
0
]);
File
file
=
new
File
(
args
[
0
]);
if
(!
file
.
exists
())
{
System
.
out
.
println
(
"file not found"
);
return
;
}
String
fileDictory
=
file
.
getParent
();
String
filename
=
file
.
getName
();
String
outDictory
=
fileDictory
+
'/'
+
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
"."
));
File
outFile
=
new
File
(
outDictory
);
if
(!
outFile
.
exists
())
{
outFile
.
mkdirs
();
}
else
{
File
[]
files
=
outFile
.
listFiles
();
//声明目录下所有的文件 files[];
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
//遍历目录下所有的文件
files
[
i
].
delete
();
//把每个文件用这个方法进行迭代
}
}
System
.
out
.
println
(
"开始处理"
);
long
startTime
=
System
.
currentTimeMillis
();
//获取开始时间
if
(
checkFile
(
file
))
{
doPPTtoImage
(
file
,
outDictory
);
}
else
{
doPPTXtoImage
(
file
,
outDictory
);
}
long
endTime
=
System
.
currentTimeMillis
();
//获取结束时间
System
.
out
.
println
(
"程序运行时间: "
+
(
endTime
-
startTime
)
+
"ms"
);
System
.
out
.
println
(
"处理结束"
);
}
/**
* @param file
* @param outPut
* @return
*/
public
static
boolean
doPPTXtoImage
(
File
file
,
String
outPut
)
{
try
{
FileInputStream
is
=
new
FileInputStream
(
file
);
XMLSlideShow
ppt
=
new
XMLSlideShow
(
is
);
is
.
close
();
Dimension
pgsize
=
ppt
.
getPageSize
();
java
.
util
.
List
<
XSLFSlide
>
slides
=
ppt
.
getSlides
();
int
total
=
slides
.
size
();
for
(
int
i
=
0
;
i
<
slides
.
size
();
i
++)
{
XSLFSlide
xslfSlide
=
slides
.
get
(
i
);
System
.
out
.
println
(
"共"
+
total
+
"页, 第"
+
(
i
+
1
)
+
"页。"
);
BufferedImage
img
=
new
BufferedImage
(
pgsize
.
width
,
pgsize
.
height
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics2D
graphics
=
img
.
createGraphics
();
graphics
.
setPaint
(
Color
.
white
);
graphics
.
fill
(
new
Rectangle2D
.
Float
(
0
,
0
,
pgsize
.
width
,
pgsize
.
height
));
xslfSlide
.
draw
(
graphics
);
// 这里设置图片的存放路径和图片的格式(jpeg,png,bmp等等),注意生成文件路径
FileOutputStream
out
=
new
FileOutputStream
(
outPut
+
"/image_"
+
(
i
+
1
)
+
".jpg"
);
javax
.
imageio
.
ImageIO
.
write
(
img
,
"jpg"
,
out
);
out
.
close
();
}
return
true
;
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
e
);
}
catch
(
IOException
e
)
{
}
return
false
;
}
/**
* @param file
* @param outPut
* @return
*/
public
static
boolean
doPPTtoImage
(
File
file
,
String
outPut
)
{
try
{
FileInputStream
is
=
new
FileInputStream
(
file
);
HSLFSlideShow
ppt
=
new
HSLFSlideShow
(
is
);
is
.
close
();
Dimension
pgsize
=
ppt
.
getPageSize
();
java
.
util
.
List
<
HSLFSlide
>
slides
=
ppt
.
getSlides
();
int
total
=
slides
.
size
();
for
(
int
i
=
0
;
i
<
slides
.
size
();
i
++)
{
HSLFSlide
hslfSlide
=
slides
.
get
(
i
);
System
.
out
.
println
(
"共"
+
total
+
"页, 第"
+
(
i
+
1
)
+
"页。"
);
BufferedImage
img
=
new
BufferedImage
(
pgsize
.
width
,
pgsize
.
height
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics2D
graphics
=
img
.
createGraphics
();
graphics
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
graphics
.
setRenderingHint
(
RenderingHints
.
KEY_RENDERING
,
RenderingHints
.
VALUE_RENDER_QUALITY
);
graphics
.
setRenderingHint
(
RenderingHints
.
KEY_INTERPOLATION
,
RenderingHints
.
VALUE_INTERPOLATION_BICUBIC
);
graphics
.
setRenderingHint
(
RenderingHints
.
KEY_FRACTIONALMETRICS
,
RenderingHints
.
VALUE_FRACTIONALMETRICS_ON
);
graphics
.
setPaint
(
Color
.
white
);
graphics
.
fill
(
new
Rectangle2D
.
Float
(
0
,
0
,
pgsize
.
width
,
pgsize
.
height
));
hslfSlide
.
draw
(
graphics
);
// 这里设置图片的存放路径和图片的格式(jpeg,png,bmp等等),注意生成文件路径
FileOutputStream
out
=
new
FileOutputStream
(
outPut
+
"image_"
+
(
i
+
1
)
+
".jpg"
);
javax
.
imageio
.
ImageIO
.
write
(
img
,
"jpg"
,
out
);
out
.
close
();
break
;
}
return
true
;
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
e
);
// System.out.println("Can't find the image!");
}
catch
(
IOException
e
)
{
}
return
false
;
}
/**
* @param file
* @return
*/
public
static
boolean
checkFile
(
File
file
)
{
boolean
isppt
=
false
;
String
filename
=
file
.
getName
();
if
(
filename
!=
null
&&
filename
.
indexOf
(
"."
)
!=
-
1
)
{
String
suffixname
=
filename
.
substring
(
filename
.
indexOf
(
"."
));
if
(
suffixname
.
equals
(
".ppt"
))
{
isppt
=
true
;
}
return
isppt
;
}
else
{
return
isppt
;
}
}
}
src/test/java/.gitignore
0 → 100644
View file @
e447c353
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