https://bz.apache.org/bugzilla/show_bug.cgi?id=59061
Bug ID: 59061 Summary: Want to create Template(potx) file using Apache POI.And using that potx wants to create pptx file. Product: POI Version: 3.13-FINAL Hardware: PC Status: NEW Severity: normal Priority: P2 Component: XSLF Assignee: dev@poi.apache.org Reporter: rahul.kr.sharm...@gmail.com Hi I am trying to create a template file(with .potx file name extension) and using the template as base wants to create pptx file. I am trying to create template file using a image file as background of slide but the generated potx file doesn't have any background image, file has been created with blank slide. I used the bellow Code: public class CreateTemplate { public static void main(String[] args) throws Exception { String imgPathStr = System.getProperty("user.dir") + "/src/resources/images/TestSameChnl_001_t.jpg"; File imgFile = new File(imgPathStr); File potxFile = new File(System.getProperty("user.dir") + "/src/resources/Examples/layout_v0.potx"); FileOutputStream out = new FileOutputStream(potxFile); XMLSlideShow ppt = new XMLSlideShow(); //creating a slide in it XSLFSlide slide = ppt.createSlide(); byte[] rawData = getRawBytesFromFile(imgPathStr); // some code to read raw bytes from image file ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(rawData)); BufferedImage img = ImageIO.read(iis); Dimension dimension = ppt.getPageSize(); // XSLFShape[] shapes = slide.getShapes(); // BufferedImage img = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); // graphics.setPaint(f); graphics.fill(new Rectangle2D.Float(0, 0, dimension.width, dimension.height)); slide.draw(graphics);//getBackground().setLineColor(Color.GREEN);//tFillColor(Color.GREEN);//draw(graphics); ppt.write(out); System.out.println("image added successfully"); out.close(); } private static byte[] getRawBytesFromFile(String path) throws FileNotFoundException, IOException { byte[] image; File file = new File(path); image = new byte[(int)file.length()]; FileInputStream fileInputStream = new FileInputStream(file); fileInputStream.read(image); return image; } } After creating potx file I am trying to create pptx file using potx file and used the bellow Java code: import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.DecimalFormat; import javax.imageio.ImageIO; import javax.imageio.stream.ImageInputStream; import org.apache.poi.sl.usermodel.PictureData; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFPictureData; import org.apache.poi.xslf.usermodel.XSLFSlide; /** * * @author rahul.sharma */ public class PPTWithPotx_Template_Example { static DecimalFormat df_time = new DecimalFormat("0.####"); public static void main(String[] args) throws Exception{ File imgFile = new File(System.getProperty("user.dir")+"/src/resources/images/TestSameChnl_001_t.jpg"); File potx_File = new File(System.getProperty("user.dir") + "/src/resources/Examples/layout_v0.potx" ); File pptx_File = new File(System.getProperty("user.dir") + "/src/resources/Examples/PPTWithTemplate.pptx" ); File movieFile = new File(System.getProperty("user.dir") + "/src/resources/movie/Dummy.mp4"); FileInputStream ins = new FileInputStream(potx_File); FileOutputStream out = new FileOutputStream(pptx_File); XMLSlideShow ppt = new XMLSlideShow(ins); XSLFSlide slide = ppt.createSlide(); byte[] rawData = getRawBytesFromFile(imgFile.getAbsolutePath()); // some code to read raw bytes from image file ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(rawData)); BufferedImage img = ImageIO.read(iis); XSLFPictureData pictureData = ppt.addPicture(rawData, PictureData.PictureType.JPEG); ppt.write(out); out.close(); } private static byte[] getRawBytesFromFile(String path) throws FileNotFoundException, IOException { byte[] image; File file = new File(path); image = new byte[(int)file.length()]; FileInputStream fileInputStream = new FileInputStream(file); fileInputStream.read(image); return image; } } Please help me to generate pots file and then from potx to ppt. Thanks in advance. Thanks & Regards Rahul Kumar Sharma. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org