Commit de26c439 authored by 夏彬's avatar 夏彬

修改程序

parent 09a7efde
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
<artifactId>ppttoimages</artifactId> <artifactId>ppttoimages</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<repositories> <repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/lib</url>
</repository>
<repository> <repository>
<id>ppcc-public</id> <id>ppcc-public</id>
<name>Nexus Release Repository</name> <name>Nexus Release Repository</name>
...@@ -16,27 +21,11 @@ ...@@ -16,27 +21,11 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>com.aspose</groupId>
<artifactId>poi</artifactId> <artifactId>aspose-slides</artifactId>
<version>3.15</version> <version>15.9.0</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> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
...@@ -44,6 +33,7 @@ ...@@ -44,6 +33,7 @@
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>1.4</version> <version>1.4</version>
<executions> <executions>
<!-- Run shade goal on package phase --> <!-- Run shade goal on package phase -->
<execution> <execution>
<phase>package</phase> <phase>package</phase>
...@@ -51,29 +41,17 @@ ...@@ -51,29 +41,17 @@
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <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> <transformers>
<transformer <transformermvn
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cc.pp.PptToImages</mainClass> <mainClass>cc.pp.PptToImages</mainClass>
</transformer> </transformermvn>
</transformers> </transformers>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
......
package cc.pp; package cc.pp;
import org.apache.poi.hslf.usermodel.HSLFSlide; import com.aspose.slides.*;
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.io.File;
import java.awt.geom.Rectangle2D; import java.io.InputStream;
import java.awt.image.BufferedImage;
import java.io.*;
/** /**
* Created by xiabin on 2016/11/30. * Created by xiabin on 2016/11/30.
*/ */
class CustomFormattingController implements IHtmlFormattingController {
private String SlideHeader = "<html><head><meta http-equiv=\"Content-Type\" Content=\"text/html\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"><style type=\"text/css\">body {margin:0;} \nsvg {width:100%;height:100%;}</style></head><body><div class=\"slide\" name=\"slide\" >";
private String SlideFooter = "</div></body></html>";
public CustomFormattingController() {
}
public void writeDocumentStart(IHtmlGenerator generator, IPresentation presentation) {
}
public void writeDocumentEnd(IHtmlGenerator generator, IPresentation presentation) {
}
public void writeSlideStart(IHtmlGenerator generator, ISlide slide) {
generator.addHtml(SlideHeader);
}
public void writeSlideEnd(IHtmlGenerator generator, ISlide slide) {
generator.addHtml(SlideFooter);
}
public void writeShapeStart(IHtmlGenerator generator, IShape shape) {
}
public void writeShapeEnd(IHtmlGenerator generator, IShape shape) {
}
}
/** /**
* main * main
*/ */
public class PptToImages { public class PptToImages {
private static boolean getLicense() {
boolean result = false;
try {
License aposeLic = new License();
InputStream is = PptToImages.class.getResourceAsStream("/license.xml");
System.out.println(PptToImages.class.getResource("/license.xml"));
aposeLic.setLicense(is);
is.close();
//InputStream is = GetLicense.class.getClassLoader().getResourceAsStream("D:\\software\\word2pdf\\Aspose.Total.lic");
//License aposeLic = new License();
//aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/** /**
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
if (!PptToImages.getLicense()) {
System.out.println("证书错误");
return;
}
// 读入PPT文件 // 读入PPT文件
if (args.length != 1) { if (args.length != 1) {
System.out.println("Usage:"); System.out.println("Usage:");
...@@ -49,123 +95,36 @@ public class PptToImages { ...@@ -49,123 +95,36 @@ public class PptToImages {
System.out.println("开始处理"); System.out.println("开始处理");
long startTime = System.currentTimeMillis(); //获取开始时间 long startTime = System.currentTimeMillis(); //获取开始时间
if (checkFile(file)) { doPPTtOrPPTXoImage(file, outDictory);
doPPTtoImage(file, outDictory);
} else {
doPPTXtoImage(file, outDictory);
}
long endTime = System.currentTimeMillis(); //获取结束时间 long endTime = System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间: " + (endTime - startTime) + "ms"); System.out.println("程序运行时间: " + (endTime - startTime) + "ms");
System.out.println("处理结束"); System.out.println("处理结束");
} }
/** public static void doPPTtOrPPTXoImage(File file, String outPut) {
* @param file String htmlDir = outPut;
* @param outPut Presentation pres = new Presentation(file.getAbsolutePath());
* @return
*/
public static boolean doPPTXtoImage(File file, String outPut) {
try { try {
FileInputStream is = new FileInputStream(file); System.out.println("开始转换" + file.getName() + " to " + htmlDir);
XMLSlideShow ppt = new XMLSlideShow(is); // Setting HTML Optionsls
is.close(); HtmlOptions opts = new HtmlOptions();
Dimension pgsize = ppt.getPageSize(); opts.setHtmlFormatter(HtmlFormatter.createCustomFormatter(new CustomFormattingController()));
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();
} // Saving to individual files
return true; int total = pres.getSlides().size();
} catch (FileNotFoundException e) {
System.out.println(e);
} catch (IOException e) {
System.out.println(e);
} catch (Exception e) {
System.out.println(e);
}
return false;
}
/** for (int i = 0; i < total; i++) {
* @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) + "页。"); System.out.println("共" + total + "页, 第" + (i + 1) + "页。");
pres.save(htmlDir + "/slide_" + (i + 1) + ".html", new int[]{i + 1}, SaveFormat.Html, opts);
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();
} }
return true;
} catch (FileNotFoundException e) {
System.out.println(e);
} catch (IOException e) {
System.out.println(e);
} catch (Exception e) {
System.out.println(e);
}
return false;
}
/** } catch (Exception ex) {
* @param file System.out.println(ex);
* @return } finally {
*/ if (pres != null)
public static boolean checkFile(File file) { pres.dispose();
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;
} }
} }
} }
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Slides for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment