0

I am experimenting with google image api and apache poi api. also getting exception: org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

my souce code is given below:

import com.google.appengine.api.blobstore.BlobstoreInputStream;
import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;

 XMLSlideShow ppt= new XMLSlideShow(BlobstoreInputStream);

 //getting the dimensions and size of the slide 
 //Dimension pgsize = ppt.getPageSize();
 XSLFSlide[] slide = ppt.getSlides();    
 for (int i = 0; i < slide.length; i++) {

     PackagePart part= slide[i].getPackagePart();
     OutputStream outputStream = part.getOutputStream();
     ImagesService imagesService = ImagesServiceFactory.getImagesService();
     ppt.write(outputStream);
     ByteArrayOutputStream bout=(((ByteArrayOutputStream) outputStream));
     Image img = ImagesServiceFactory.makeImage(bout.toByteArray());

     /* BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = img.createGraphics();

    //clear the drawing area
    graphics.setPaint(Color.white);
    graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

    //render
    slide[i].draw(graphics);
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  */ 

    byte[] nimg=img.getImageData();
abhi169jais
  • 125
  • 1
  • 6

2 Answers2

0

If you need just pictures from the PPTX you do not need Apache poi for that. A pptx file is just a zipped file and images are store in root/media/* SO just open the zip and read all images. Use the following code.

URL zipUrl = Main.class.getResource("/resources/zipfile.zip");
File zipFile = new File(zipUrl.toURI());
ZipFile zip = new ZipFile(zipFile);
InputStream is = zip.getInputStream(zip.getEntry("/media/image.png"));
user1615664
  • 591
  • 2
  • 11
  • 24
  • GAE do not support java graphics classes, either enable vm in google-appengine.xml file or use GCE to perform such action. – abhi169jais Nov 16 '15 at 14:50
0

The exception "org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]" is thrown when the file is Encrypted (password protected) or the file is corrupt.

You Should decrypt the file first using [XML-based formats - Decryption][1]

[1]: https://poi.apache.org/encryption.html or make sure that the file is not corrupt.

I hope this helps.