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
3252c463
Commit
3252c463
authored
Dec 27, 2016
by
夏彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改程序
parent
de26c439
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
133 additions
and
19 deletions
+133
-19
PptToImages.java
src/main/java/cc/pp/PptToImages.java
+133
-19
No files found.
src/main/java/cc/pp/PptToImages.java
View file @
3252c463
...
...
@@ -2,6 +2,8 @@ package cc.pp;
import
com.aspose.slides.*
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.InputStream
;
...
...
@@ -60,6 +62,25 @@ public class PptToImages {
return
result
;
}
/**
* @param error
*/
static
void
usage
(
String
error
)
{
String
msg
=
"Usage: PptToImages [options] <ppt or pptx file>\n"
+
(
error
==
null
?
""
:
(
"Error: "
+
error
+
"\n"
))
+
"Options:\n"
+
" -format <type> png,gif,jpg\n"
+
" -scale <float> scale factor\n"
+
" -outdir <dir> output directory, defaults to origin of the ppt/pptx file\n"
+
" -type <type> image,html format for output\n"
+
" -quiet do not write to console (for normal processing)\n"
;
System
.
out
.
println
(
msg
);
// no System.exit here, as we also run in junit tests!
}
/**
* @param args
*/
...
...
@@ -69,45 +90,105 @@ public class PptToImages {
return
;
}
// 读入PPT文件
if
(
args
.
length
!=
1
)
{
System
.
out
.
println
(
"Usage:"
);
System
.
out
.
println
(
" command file"
);
if
(
args
.
length
==
0
)
{
usage
(
null
);
return
;
}
String
type
=
"image"
;
File
file
=
null
;
String
format
=
"jpg"
;
String
outDictory
=
null
;
boolean
quiet
=
false
;
Float
scale
=
1
f
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
args
[
i
].
startsWith
(
"-"
))
{
if
(
"-scale"
.
equals
(
args
[
i
]))
{
scale
=
Float
.
parseFloat
(
args
[++
i
]);
}
else
if
(
"-format"
.
equals
(
args
[
i
]))
{
format
=
args
[++
i
];
}
else
if
(
"-outdir"
.
equals
(
args
[
i
]))
{
outDictory
=
args
[++
i
];
}
else
if
(
"-type"
.
equals
(
args
[
i
]))
{
type
=
args
[++
i
];
}
else
if
(
"-quiet"
.
equals
(
args
[
i
]))
{
quiet
=
true
;
}
}
else
{
file
=
new
File
(
args
[
i
]);
}
}
if
(
file
==
null
||
!
file
.
exists
())
{
usage
(
"File not specified or it doesn't exist"
);
return
;
}
System
.
out
.
println
(
"文件名:"
+
args
[
0
]);
File
file
=
new
File
(
args
[
0
]);
if
(!
file
.
exists
())
{
System
.
out
.
println
(
"file not found"
);
if
(!
format
.
matches
(
"^(png|gif|jpg)$"
))
{
usage
(
"Invalid format given"
);
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
();
if
(!
type
.
matches
(
"^(image|html)$"
))
{
usage
(
"Invalid type format given"
);
return
;
}
if
(
scale
<
0
)
{
usage
(
"Invalid scale given"
);
return
;
}
if
(
outDictory
==
null
)
{
String
fileDictory
=
file
.
getParent
();
String
filename
=
file
.
getName
();
outDictory
=
fileDictory
+
'/'
+
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
"."
));
}
File
outD
=
new
File
(
outDictory
);
if
(!
outD
.
exists
())
{
outD
.
mkdirs
();
}
else
{
File
[]
files
=
out
File
.
listFiles
();
//声明目录下所有的文件 files[];
File
[]
files
=
out
D
.
listFiles
();
//声明目录下所有的文件 files[];
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
//遍历目录下所有的文件
files
[
i
].
delete
();
//把每个文件用这个方法进行迭代
}
}
System
.
out
.
println
(
"开始处理"
);
if
(!
quiet
)
{
System
.
out
.
println
(
"Processing "
+
file
);
}
long
startTime
=
System
.
currentTimeMillis
();
//获取开始时间
doPPTtOrPPTXoImage
(
file
,
outDictory
);
if
(
type
.
equals
(
"image"
))
{
if
(!
quiet
)
{
System
.
out
.
println
(
"image"
);
}
doPPTtOrPPTXoImage
(
file
,
outDictory
,
format
,
scale
,
quiet
);
}
else
{
if
(!
quiet
)
{
System
.
out
.
println
(
"html"
);
}
doPPTtOrPPTXoHtml
(
file
,
outDictory
,
quiet
);
}
long
endTime
=
System
.
currentTimeMillis
();
//获取结束时间
System
.
out
.
println
(
"程序运行时间: "
+
(
endTime
-
startTime
)
+
"ms"
);
System
.
out
.
println
(
"处理结束"
);
}
public
static
void
doPPTtOrPPTXo
Image
(
File
file
,
String
outPu
t
)
{
public
static
void
doPPTtOrPPTXo
Html
(
File
file
,
String
outPut
,
Boolean
quie
t
)
{
String
htmlDir
=
outPut
;
Presentation
pres
=
new
Presentation
(
file
.
getAbsolutePath
());
try
{
System
.
out
.
println
(
"开始转换"
+
file
.
getName
()
+
" to "
+
htmlDir
);
if
(!
quiet
)
{
System
.
out
.
println
(
"开始转换"
+
file
.
getName
()
+
" to "
+
htmlDir
);
}
// Setting HTML Optionsls
HtmlOptions
opts
=
new
HtmlOptions
();
opts
.
setHtmlFormatter
(
HtmlFormatter
.
createCustomFormatter
(
new
CustomFormattingController
()));
...
...
@@ -116,7 +197,10 @@ public class PptToImages {
int
total
=
pres
.
getSlides
().
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++)
{
System
.
out
.
println
(
"共"
+
total
+
"页, 第"
+
(
i
+
1
)
+
"页。"
);
if
(!
quiet
)
{
System
.
out
.
println
(
"共"
+
total
+
"页, 第"
+
(
i
+
1
)
+
"页。"
);
}
pres
.
save
(
htmlDir
+
"/slide_"
+
(
i
+
1
)
+
".html"
,
new
int
[]{
i
+
1
},
SaveFormat
.
Html
,
opts
);
}
...
...
@@ -127,4 +211,34 @@ public class PptToImages {
pres
.
dispose
();
}
}
public
static
void
doPPTtOrPPTXoImage
(
File
file
,
String
outPut
,
String
format
,
Float
scale
,
Boolean
quiet
)
{
String
htmlDir
=
outPut
;
Presentation
pres
=
new
Presentation
(
file
.
getAbsolutePath
());
try
{
if
(!
quiet
)
{
System
.
out
.
println
(
"开始转换"
+
file
.
getName
()
+
" to "
+
htmlDir
);
}
// Saving to individual files
int
total
=
pres
.
getSlides
().
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++)
{
if
(!
quiet
)
{
System
.
out
.
println
(
"共"
+
total
+
"页, 第"
+
(
i
+
1
)
+
"页。"
);
}
ISlide
sld
=
pres
.
getSlides
().
get_Item
(
i
);
BufferedImage
image
=
sld
.
getThumbnail
(
scale
,
scale
);
ImageIO
.
write
(
image
,
format
,
new
File
(
htmlDir
+
"/slide_"
+
(
i
+
1
)
+
"."
+
format
));
}
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
ex
);
}
finally
{
if
(
pres
!=
null
)
pres
.
dispose
();
}
}
}
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