You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/04/05 13:27:18 UTC

[Bug 59273] New: Unable to create pptx file by potx file using Apache POI

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

            Bug ID: 59273
           Summary: Unable to create pptx file by potx file using Apache
                    POI
           Product: POI
           Version: 3.13-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSLF
          Assignee: dev@poi.apache.org
          Reporter: rahul.kr.sharma29@gmail.com

Created attachment 33728
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33728&action=edit
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()) {
                System.out.println(layout.getType());
            }
        }

        // 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");

        ppt.write(out);
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59273] Unable to create pptx file by potx file using Apache POI

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59273

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59273] Unable to create pptx file by potx file using Apache POI

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59273

Andreas Beeker <ki...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |59061


Referenced Bugs:

https://bz.apache.org/bugzilla/show_bug.cgi?id=59061
[Bug 59061] How to create PPTX using power-point-template file
-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59273] Unable to create pptx file by potx file using Apache POI

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59273

--- Comment #3 from Andreas Beeker <ki...@apache.org> ---
*** Bug 59061 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59273] Unable to create pptx file by potx file using Apache POI

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59273

--- Comment #1 from Andreas Beeker <ki...@apache.org> ---
The trick is to change the content-type of the presentation:

ppt.getPackage().replaceContentType(
XSLFRelation.PRESENTATIONML_TEMPLATE, XSLFRelation.MAIN
);

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

I'm on it ...

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59273] Unable to create pptx file by potx file using Apache POI

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59273

Andreas Beeker <ki...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Andreas Beeker <ki...@apache.org> ---
The content-type replacement was fixed via r1769220

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org