https://bz.apache.org/bugzilla/show_bug.cgi?id=60552

            Bug ID: 60552
           Summary: PPTX generated using POI can't be opened with
                    Microsoft Powerpoint
           Product: POI
           Version: 3.15-FINAL
          Hardware: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: XSLF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

I am using a pptx as a reference to create another pptx file. Its used more
like a template. When I generate the ppt and open it in MS PowerPoint 2016
(same is seen on a Mac version too) it gives typical "PowerPoint found a
problem with the content ...". I have tried all the usual PowerPoint tricks to
see if it's a security issue. Does not seem so.
I was having issue with POI 3.9. So I downloaded 3.15 from
http://www-eu.apache.org/dist/poi/release/bin/poi-bin-3.15-20160924.zip but
continue to have the same issue.

Following are the relevant code snippets: In the process of removing the
proprietary code, I may have made some small mistakes but the PPT generation
part is intact. 

        private byte[] resizeImage(byte[] inPic, double img_width, double
img_height) {
                try {
                        ByteArrayInputStream in = new
ByteArrayInputStream(inPic);
                        BufferedImage originalImage = ImageIO.read(in);
                        int type = originalImage.getType() == 0 ?
BufferedImage.TYPE_INT_ARGB : originalImage.getType();

                        if (img_height == 0) {
                                img_height = originalImage.getHeight();
                        }

                        BufferedImage resizedImage = new BufferedImage((int)
img_width, (int) img_height, type);
                        Graphics2D g = resizedImage.createGraphics();
                        g.drawImage(originalImage, 0, 0, (int) img_width, (int)
img_height, null);
                        g.dispose();

                        ByteArrayOutputStream buffer = new
ByteArrayOutputStream();
                        ImageIO.write(resizedImage, "jpeg", buffer);
                        return buffer.toByteArray();
                } catch (Exception ex) {

                }
                return null;
        }

        private XSLFShape getShape(BLogger logger, XSLFSlide slide, String
shapeName) {
                XSLFShape shape = null;
                Iterator<XSLFShape> sit =
slide.getSlideLayout().getShapes().iterator();
                while(sit.hasNext()) {
                        XSLFShape lshape = sit.next();
                        if (lshape != null &&
lshape.getShapeName().equalsIgnoreCase(shapeName)) {
                                shape = lshape;
                                break;
                        }
                }
                return shape;
        }

        private static void setPic(XMLSlideShow ppt, XSLFSlide slide, byte[]
pic, String shapeName) throws BException {
                XSLFShape shape = getShape(logger, slide, shapeName);

                Rectangle2D anchor = shape.getAnchor();
                byte[] ri = resizeImage(pic, anchor.getWidth(),
anchor.getHeight());
                XSLFPictureData pd = ppt.addPicture(pic, PictureType.JPEG);
                XSLFPictureShape pic = slide.createPicture(pd);
                slide.removeShape(shape);
                pic.setAnchor(anchor);
        }

        public static XSLFSlide createSlide(XMLSlideShow ppt, XSLFSlide slide,
                        Map<XSLFSlide, XSLFSlide> srcDstrcSlideMap, 
                        Set<XSLFSlideLayout> visitedLOs) {
                slide = ppt.createSlide();

                XSLFSlideLayout srcLayout = cachedSlide.getSlideLayout();
//this is coming from a cached slide
                if (!visitedLOs.contains(srcLayout)) {
                        visitedLOs.add(srcLayout);
                        XSLFSlideLayout dstLayout = slide.getSlideLayout();
                        dstLayout.importContent(srcLayout);
                }
                slide.importContent(pptlo.slide);
                return slide;
        }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to