Android项目记录点滴

时间:2024-01-14 14:41:44

服务器端:(根据Apache POI库函数其中SlideShow表示PPT文档,Slide表示某一张幻灯片)

1.先把电脑中的PPT文件读入到一个字节数组中。(输入流-->字节数组-->输出流-->字节数组)

FileInputStream inputStream = new FileInputStream(Path);

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byte[] byffer = new byte[1024];
    int length = -1;
    while ((length = is.read(byffer)) != -1) {
    byteArrayOutputStream.write(byffer, 0, length);

}
    byteArrayOutputStream.close();
    byte[]  fileBuffer = byteArrayOutputStream.toByteArray();

2.创建SlideShow(把PPT输入流转为SlideShow)

(Apache POI库函数SlideShow(java.io.InputStream inputStream)Constructs a Powerpoint document from an input stream.

FileInputStream inputStream = new FileInputStream(Path);

SlideShow ppt = new SlideShow(is);

如果是pptx格式的PPT,则,XMLSlideShow pptx = new XMLSlideShow(is);

3.获取幻灯片数组

Slide slide = ppt.getSlides();

如果是pptx格式的PPT,则,XSLFSlide slidePPTx = pptx.getSlides();

4.使用batik操作SVG图片(生成DOM树)

DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
Document doc = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);

5.渲染doc (Document 为存放PPT或pptx的XML数据结构)

SVGGraphics2D graphics = new SVGGraphics2D(doc);
graphics.setSVGCanvasSize( pgsize);
graphics.setPaint(Color.white);

slide[currentPage - 1].draw(graphics);
Element svgRoot = doc.getDocumentElement();
graphics.getRoot(svgRoot);

6.在画布中展示PPT转化为的SVG图片

JSVGCanvas _svgCanvas = new JSVGCanvas();

_svgCanvas.setDocument(doc);