Bug 59273 - Unable to create pptx file by potx file using Apache POI
Summary: Unable to create pptx file by potx file using Apache POI
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 3.13-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
: 59061 (view as bug list)
Depends on:
Blocks: 59061
  Show dependency tree
Reported: 2016-04-05 11:27 UTC by Rahul
Modified: 2018-05-18 17:08 UTC (History)
0 users

Potx file by which I want to create pptx. (603.36 KB, application/vnd.openxmlformats-officedocument.presentationml.template)
2016-04-05 11:27 UTC, Rahul

Note You need to log in before you can comment on or make changes to this bug.
Description Rahul 2016-04-05 11:27:18 UTC
Created attachment 33728 [details]
Potx file by which I want to create pptx.

Hi I am trying to create power-point presentation(pptx) file with potx power point presentation template using Apache POI. The file was generated but giving error "The File format or File extension is not valid Verify that the file has not been corrupted and that the file extension matches the format of the file." when trying to open it up . I am using below code Kindly see what I am doing wrong.

public static void createPPTXWithPOTX() throws Exception

        File potx_File = new File(System.getProperty("user.dir") + "/src/resources/Examples/SelfMadePOTX.potx");

        File pptx_File = new File(System.getProperty("user.dir") + "/src/resources/Examples/PPTWithTemplate12.pptx");

        FileInputStream ins = new FileInputStream(potx_File);
        FileOutputStream out = new FileOutputStream(pptx_File);
        XMLSlideShow ppt = new XMLSlideShow(ins);
        // first see what slide layouts are available :
        System.out.println("Available slide layouts:");
        for (XSLFSlideMaster master : ppt.getSlideMasters()) {
            for (XSLFSlideLayout layout : master.getSlideLayouts()) {

        // blank slide
        XSLFSlide blankSlide = ppt.createSlide();
    // there can be multiple masters each referencing a number of layouts
        // for demonstration purposes we use the first (default) slide master
        XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];
        // title slide
        XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
        // fill the placeholders
        XSLFSlide slide1 = ppt.createSlide(titleLayout);
        XSLFTextShape title1 = slide1.getPlaceholder(0);
        title1.setText("First Title");

        // title and content
        XSLFSlideLayout titleBodyLayout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
        XSLFSlide slide2 = ppt.createSlide(titleBodyLayout);

        XSLFTextShape title2 = slide2.getPlaceholder(0);
        title2.setText("Second Title");

        XSLFTextShape body2 = slide2.getPlaceholder(1);
        body2.clearText(); // unset any existing text
        body2.addNewTextParagraph().addNewTextRun().setText("First paragraph");
        body2.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
        body2.addNewTextParagraph().addNewTextRun().setText("Third paragraph");

Comment 1 Andreas Beeker 2016-11-10 09:41:15 UTC
The trick is to change the content-type of the presentation:


... but the new content type is not saved.

I'm on it ...
Comment 2 Andreas Beeker 2016-11-10 22:57:00 UTC
The content-type replacement was fixed via r1769220
Comment 3 Andreas Beeker 2018-05-18 17:08:12 UTC
*** Bug 59061 has been marked as a duplicate of this bug. ***