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/02/24 11:25:32 UTC
[Bug 59061] New: Want to create Template(potx) file using Apache
POI.And using that potx wants to create pptx file.
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.sharma29@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-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59061] How to create PPTX using power-point-template file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59061
Rahul <ra...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Want to create |How to create PPTX using
|Template(potx) file using |power-point-template file
|Apache POI.And using that |
|potx wants to create pptx |
|file. |
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 59061] How to create PPTX using power-point-template file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59061
--- Comment #1 from Rahul <ra...@gmail.com> ---
Hi I want to create power-point presentation using power-point-template(which
may be already exists or may be generated by poi.) for creating power point
template file which have a background image in the slides, I write the
following code which creates template file which opens in open-office but
giving error to opening in Microsoft-power-point.
The Code is
private static void generatePOTX() throws IOException, FileNotFoundException {
String imgPathStr = System.getProperty("user.dir") +
"/src/resources/images/TestSameChnl_001_t.jpeg";
File imgFile = new File(imgPathStr);
File potxFile = new File(System.getProperty("user.dir") +
"/src/resources/Examples/layout.potx");
FileOutputStream out = new FileOutputStream(potxFile);
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
HSLFFill fill = slide.getBackground().getFill();
HSLFPictureData pd = ppt.addPicture(imgFile,
PictureData.PictureType.JPEG);
fill.setFillType(HSLFFill.FILL_PICTURE);
fill.setPictureData(pd);
ppt.write(out);
out.close();
}
After that I tried to create a PPT file using the generated POTX file but But
it's giving error. I am trying bellow code for this. And the code is
private static void GeneratePPTXUsingPOTX() throws FileNotFoundException,
IOException {
File imgFile = new
File(System.getProperty("user.dir")+"/src/resources/images/TestSameChnl_001_t.jpeg");
File potx_File = new File(System.getProperty("user.dir") +
"/src/resources/Examples/layout.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);
HSLFSlideShow ppt = new HSLFSlideShow(ins);
List<HSLFSlide> slideList = ppt.getSlides();
int movieIdx = ppt.addMovie(movieFile.getAbsolutePath(),
MovieShape.MOVIE_MPEG);
HSLFPictureData pictureData = ppt.addPicture(imgFile,
PictureData.PictureType.JPEG);
MovieShape shape = new MovieShape(movieIdx, pictureData);
shape.setAnchor(new java.awt.Rectangle(300,225,420,280));
slideList.get(0).addShape(shape);
shape.setAutoPlay(true);
ppt.write(out);
out.close();
}
And the exception which is coming is as fallows:
java.lang.NullPointerException at
org.apache.poi.hslf.usermodel.HSLFPictureShape.afterInsert(HSLFPictureShape.java:185)
at org.apache.poi.hslf.usermodel.HSLFSheet.addShape(HSLFSheet.java:189)
I used this code on poi-3.13-20150929.jar as well as
poi-3.14-beta1-20151223.jar the latest one and both have the same result.
Please suggest me what should I do.
Thanks
--
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 59061] How to create PPTX using power-point-template file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59061
Andreas Beeker <ki...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Hardware|PC |All
Depends on| |59273
Referenced Bugs:
https://bz.apache.org/bugzilla/show_bug.cgi?id=59273
[Bug 59273] Unable to create pptx file by potx file using Apache POI
--
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 59061] How to create PPTX using power-point-template file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59061
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|3.13-FINAL |3.14-FINAL
--
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 59061] How to create PPTX using power-point-template file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59061
Andreas Beeker <ki...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #2 from Andreas Beeker <ki...@apache.org> ---
*** This bug has been marked as a duplicate of bug 59273 ***
--
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