1 2 3 4 5 6 |
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-slides</artifactId> <version>16.7.0</version> <!--<version>17.5-jdk16</version>--> </dependency> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
package com.pandy.aspose; import com.aspose.slides.ISlide; import com.aspose.slides.License; import com.aspose.slides.Presentation; import com.aspose.slides.SaveFormat; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; /** * <version>16.7.0</version> * 由于ASPOSE比较吃内存,操作大一点的文件就会堆溢出,所以请先设置好java虚拟机参数:-Xms1024m -Xmx1024m(参考值)<br> */ public class TestSlides { private static InputStream license; /** * 获取license * * @return */ public static boolean setLicense() { boolean result = false; try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); license = new FileInputStream(loader.getResource("license.xml").getPath());// 凭证文件 License aposeLic = new License(); aposeLic.setLicense(license); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } private static void covToPDF(Presentation pres) { try { //输出一个pdf System.out.println("开始PDF"); pres.save(new FileOutputStream(new File("/home/pandy/桌面/temp/test.pdf")), SaveFormat.Pdf); } catch (Exception e) { e.printStackTrace(); } } private static void covToHTML(Presentation pres) { try { //输出一个html文件 System.out.println("开始Html"); pres.save(new FileOutputStream(new File("/home/pandy/桌面/temp/test.html")), SaveFormat.Html); } catch (Exception e) { e.printStackTrace(); } } private static void covToPageImage(Presentation pres) { try { System.out.println("开始Image"); Presentation htmlPagePres = null; for (int i = 0; i < pres.getSlides().size(); i++) { ISlide slide = pres.getSlides().get_Item(i); BufferedImage image = slide.getThumbnail(new java.awt.Dimension(800, 500)); //每一页输出一张图片 File outImage = new File("/home/pandy/桌面/temp/test" + i + ".jpg"); ImageIO.write(image, "JPG", outImage); System.out.println(outImage.getAbsoluteFile().toString()); } } catch (Exception e) { e.printStackTrace(); } } private static void covToPageHtml(Presentation pres) { try { System.out.println("开始Image"); Presentation htmlPagePres = null; for (int i = 0; i < pres.getSlides().size(); i++) { ISlide slide = pres.getSlides().get_Item(i); //每一页输出一个html文件 htmlPagePres = new Presentation(); htmlPagePres.getSlides().addClone(slide); htmlPagePres.getSlides().removeAt(0); htmlPagePres.save(new FileOutputStream(new File("/home/pandy/桌面/temp/test" + i + ".html")), SaveFormat.Html); System.out.println("/home/pandy/桌面/temp/test" + i + ".html"); } } catch (Exception e) { e.printStackTrace(); } } /** * @param args */ public static void main(String[] args) { // 验证License if (!setLicense()) { return; } try { long old = System.currentTimeMillis(); InputStream fileInput = new FileInputStream("/home/pandy/文档/test.ppt");// 待处理的文件 System.out.println("开始读取"); Presentation pres = new Presentation(fileInput); covToPDF(pres); covToHTML(pres); covToPageImage(pres); covToPageHtml(pres); long now = System.currentTimeMillis(); System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"); } catch (Exception e) { e.printStackTrace(); } } } |