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: [email protected]
Reporter: [email protected]
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: [email protected]
For additional commands, e-mail: [email protected]