You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Karthik.Gopalakrishnan" <kp...@uky.edu> on 2008/09/18 17:50:04 UTC
Using POI for ppt to image conversion
I am trying to get each slide and convert them into images. I was able to do
this with the examples i found in
http://poi.apache.org/hslf/how-to-shapes.html.
Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
Is there a way i can save each of those lines(and the bullet) into different
image files?
For eg:
1) test
2) example
I want "1) test" to go to a separate image file and " 2) example" to be
saved into a different image file.
Thanks in advance. Any help is appreciated.
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19555971.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by hanj <ji...@163.com>.
But the anchor.height always got 0 if the shp is Line. How should I do to
export the Line to image in this way?
Yegor Kozlov wrote:
>
> No, you can't save individual lines of text. However, you can save each
> shape in a separate image:
>
> for (Shape sh : slide.getShapes()){
>
> Rectangle anchor = sh.getAnchor();
> BufferedImage img = new BufferedImage(anchor .width, anchor .height,
> BufferedImage.TYPE_INT_RGB);
> Graphics2D graphics = img.createGraphics();
> sh.draw(graphics);
>
> ....
> }
>
> See the source code of org.apache.poi.hslf.model.TextPainter. You can
> re-use some of its functionality and write custom
> text renderer which would draw individual bullets and lines.
>
> Yegor
>
>> I am trying to get each slide and convert them into images. I was able to
>> do
>> this with the examples i found in
>> http://poi.apache.org/hslf/how-to-shapes.html.
>>
>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>> Is there a way i can save each of those lines(and the bullet) into
>> different
>> image files?
>>
>> For eg:
>>
>> 1) test
>> 2) example
>>
>>
>> I want "1) test" to go to a separate image file and " 2) example" to be
>> saved into a different image file.
>>
>>
>> Thanks in advance. Any help is appreciated.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p20392439.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by "Karthik.Gopalakrishnan" <kp...@uky.edu>.
Thanks a lot. It works for me.
:clap::-D
Yegor Kozlov wrote:
>
> Try trunk.
> Daily builds can be downloaded from
> http://encore.torchbox.com/poi-svn-build/
>
> Yegor
>
>> I am using poi-3.1-FINAL-20080629
>> Should i be using a different version of it?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19627127.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by Yegor Kozlov <ye...@dinom.ru>.
Try trunk.
Daily builds can be downloaded from http://encore.torchbox.com/poi-svn-build/
Yegor
> I am using poi-3.1-FINAL-20080629
> Should i be using a different version of it?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by "Karthik.Gopalakrishnan" <kp...@uky.edu>.
I am using poi-3.1-FINAL-20080629
Should i be using a different version of it?
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19620402.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by Yegor Kozlov <ye...@dinom.ru>.
Which version of POI are you using? Below is a version of your code that works for me.
SlideShow ppt = new SlideShow();
TextBox textBoxShape = new TextBox();
Slide newSlide = ppt.createSlide();
textBoxShape.setText("January\r" + "February\r" + "March\r"
+ "April");
RichTextRun rt = textBoxShape.getTextRun().getRichTextRuns()[0];
rt.setFontSize(42);
rt.setBullet(true);
rt.setBulletOffset(0);
rt.setTextOffset(50);
rt.setBulletChar('\u263A');
Rectangle anchor = new Rectangle(100, 100, 400, 300);
textBoxShape.setAnchor(anchor);
newSlide.addShape(textBoxShape);
BufferedImage img = new BufferedImage(anchor.width, anchor.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
graphics.translate(-anchor.x, -anchor.y);
graphics.setPaint(Color.white);
graphics.fill(anchor);
textBoxShape.draw(graphics);
writeToFile("text.jpeg", img);
Yegor
> Please find the attached File
>
>
> /// Here is a copy of the java file i uploaded
>
> import java.awt.Graphics2D;
> import java.awt.Rectangle;
> import java.awt.image.BufferedImage;
> import java.io.File;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
>
> import org.apache.poi.hslf.HSLFSlideShow;
> import org.apache.poi.hslf.model.AutoShape;
> import org.apache.poi.hslf.model.Background;
> import org.apache.poi.hslf.model.Line;
> import org.apache.poi.hslf.model.Picture;
> import org.apache.poi.hslf.model.Shape;
> import org.apache.poi.hslf.model.Slide;
> import org.apache.poi.hslf.model.TextBox;
> import org.apache.poi.hslf.usermodel.RichTextRun;
> import org.apache.poi.hslf.usermodel.SlideShow;
>
> import com.sun.image.codec.jpeg.ImageFormatException;
> import com.sun.image.codec.jpeg.JPEGCodec;
> import com.sun.image.codec.jpeg.JPEGImageEncoder;
>
> public class test {
> static SlideShow ppt;
> static Slide[] slides;
>
> public static void main(String[] args) {
> try {
> ppt = new SlideShow(new HSLFSlideShow("c:\\temp\\ch01.ppt"));
> slides = ppt.getSlides();
> saveTextAsImage(2);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
> public static void saveTextAsImage(int slideNumber){
> Background bgnd = slides[slideNumber].getBackground();
> BufferedImage img = new BufferedImage(ppt.getPageSize().width, ppt
> .getPageSize().height, BufferedImage.TYPE_INT_RGB);
> Graphics2D graphics = img.createGraphics();
> bgnd.draw(graphics);
> Shape[] shapes = slides[slideNumber].getShapes();
> try {
> int j = 0;
> while (j < shapes.length) {
> Rectangle anchor = shapes[j].getAnchor();
> if (shapes[j] instanceof Line) {
> Line line = (Line) shapes[j];
> line.draw(graphics);
> } else if (shapes[j] instanceof AutoShape) {
> AutoShape shape = (AutoShape) shapes[j];
> TextBox textBoxShape = new TextBox();
> Slide newSlide = ppt.createSlide();
> newSlide.addShape(textBoxShape);
> textBoxShape.setText("January\r" + "February\r" + "March\r"
> + "April");
> RichTextRun rt = textBoxShape.getTextRun().getRichTextRuns()[0];
> rt.setFontSize(42);
> rt.setBullet(true);
> rt.setBulletOffset(0);
> rt.setTextOffset(50);
> rt.setBulletChar('\u263A');
> textBoxShape.setAnchor(anchor);
> textBoxShape.draw(graphics);
> writeToFile("slide-" + slideNumber+".jpeg", img);
> }
> j++;
> }
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
> public static void writeToFile(String fileName, BufferedImage img) {
> try {
> File file = new File("c:\\temp\\" + fileName);
> FileOutputStream out;
> out = new FileOutputStream(file);
> JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
> com.sun.image.codec.jpeg.JPEGEncodeParam param = encoder
> .getDefaultJPEGEncodeParam(img);
> param.setQuality(0.7f, true);
> encoder.setJPEGEncodeParam(param);
> encoder.encode(img);
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> } catch (ImageFormatException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by "Karthik.Gopalakrishnan" <kp...@uky.edu>.
Please find the attached File
/// Here is a copy of the java file i uploaded
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.AutoShape;
import org.apache.poi.hslf.model.Background;
import org.apache.poi.hslf.model.Line;
import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.model.Shape;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.model.TextBox;
import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class test {
static SlideShow ppt;
static Slide[] slides;
public static void main(String[] args) {
try {
ppt = new SlideShow(new HSLFSlideShow("c:\\temp\\ch01.ppt"));
slides = ppt.getSlides();
saveTextAsImage(2);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void saveTextAsImage(int slideNumber){
Background bgnd = slides[slideNumber].getBackground();
BufferedImage img = new BufferedImage(ppt.getPageSize().width, ppt
.getPageSize().height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
bgnd.draw(graphics);
Shape[] shapes = slides[slideNumber].getShapes();
try {
int j = 0;
while (j < shapes.length) {
Rectangle anchor = shapes[j].getAnchor();
if (shapes[j] instanceof Line) {
Line line = (Line) shapes[j];
line.draw(graphics);
} else if (shapes[j] instanceof AutoShape) {
AutoShape shape = (AutoShape) shapes[j];
TextBox textBoxShape = new TextBox();
Slide newSlide = ppt.createSlide();
newSlide.addShape(textBoxShape);
textBoxShape.setText("January\r" + "February\r" + "March\r"
+ "April");
RichTextRun rt = textBoxShape.getTextRun().getRichTextRuns()[0];
rt.setFontSize(42);
rt.setBullet(true);
rt.setBulletOffset(0);
rt.setTextOffset(50);
rt.setBulletChar('\u263A');
textBoxShape.setAnchor(anchor);
textBoxShape.draw(graphics);
writeToFile("slide-" + slideNumber+".jpeg", img);
}
j++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void writeToFile(String fileName, BufferedImage img) {
try {
File file = new File("c:\\temp\\" + fileName);
FileOutputStream out;
out = new FileOutputStream(file);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
com.sun.image.codec.jpeg.JPEGEncodeParam param = encoder
.getDefaultJPEGEncodeParam(img);
param.setQuality(0.7f, true);
encoder.setJPEGEncodeParam(param);
encoder.encode(img);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ImageFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19575440.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by Yegor Kozlov <ye...@dinom.ru>.
Post the full code. It should be something trivial.
Yegor
> Thanks for ur quick reply.
>
> I tried that too, i get a different Null pointer exception(below):-(
>
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.poi.hslf.model.TextRun.getTextRuler(TextRun.java:672)
> at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:128)
> at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
> at ReadPPT.test2(ReadPPT.java:311)
> at test.main(test.java:14)
>
>
>
>
> Yegor Kozlov wrote:
>>
>> Call slide.addShape(textBox) first. It should help.
>>
>> Yegor
>>
>>> I dont think its a bug , i am missing something really preliminary
>>>
>>> This is the portion of the code i was trying to run( yes , its from the
>>> example on the POI page to create text with bullets)
>>>
>>> TextBox shape1 = new TextBox();
>>> shape1.setText("January\r" + "February\r" + "March\r"
>>> + "April");
>>> RichTextRun rt = shape1.getTextRun().getRichTextRuns()[0];
>>> rt.setFontSize(42);
>>> rt.setBullet(true);
>>> rt.setBulletOffset(0);
>>> rt.setTextOffset(50);
>>> rt.setBulletChar('\u263A');
>>> shape1.setAnchor(anchor);
>>> shape1.draw(graphics);
>>>
>>>
>>> Exception i get is
>>>
>>> Exception in thread "main" java.lang.NullPointerException
>>> at
>>> org.apache.poi.hslf.usermodel.RichTextRun.getCharTextPropVal(RichTextRun.java:287)
>>> at
>>> org.apache.poi.hslf.usermodel.RichTextRun.getFontColor(RichTextRun.java:518)
>>> at
>>> org.apache.poi.hslf.model.TextPainter.getAttributedString(TextPainter.java:76)
>>> at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:98)
>>> at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
>>> at ReadPPT.test2(ReadPPT.java:312)
>>> at test.main(test.java:14)
>>>
>>>
>>> Thanks
>>>
>>> Karthik
>>>
>>>
>>> Yegor Kozlov wrote:
>>>>> Is there a simple way to save a
>>>>> Textbox(org.apache.poi.hslf.model.TextBox)
>>>>> with such formatted text as an image?
>>>>>
>>>>> I see, it has a draw method but when i invoke that , i get
>>>>> NullPointerException. Does it look for any specific attribute to be
>>>>> set?
>>>>>
>>>> Post the stack trace.
>>>> If you think it is a bug, open an issue in bugzilla.
>>>>
>>>> Yegor
>>>>
>>>>> Yegor Kozlov wrote:
>>>>>> No, you can't save individual lines of text. However, you can save
>>>>>> each
>>>>>> shape in a separate image:
>>>>>>
>>>>>> for (Shape sh : slide.getShapes()){
>>>>>>
>>>>>> Rectangle anchor = sh.getAnchor();
>>>>>> BufferedImage img = new BufferedImage(anchor .width, anchor
>>>>>> .height,
>>>>>> BufferedImage.TYPE_INT_RGB);
>>>>>> Graphics2D graphics = img.createGraphics();
>>>>>> sh.draw(graphics);
>>>>>>
>>>>>> ....
>>>>>> }
>>>>>>
>>>>>> See the source code of org.apache.poi.hslf.model.TextPainter. You can
>>>>>> re-use some of its functionality and write custom
>>>>>> text renderer which would draw individual bullets and lines.
>>>>>>
>>>>>> Yegor
>>>>>>
>>>>>>> I am trying to get each slide and convert them into images. I was
>>>>>>> able
>>>>>>> to
>>>>>>> do
>>>>>>> this with the examples i found in
>>>>>>> http://poi.apache.org/hslf/how-to-shapes.html.
>>>>>>>
>>>>>>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>>>>>>> Is there a way i can save each of those lines(and the bullet) into
>>>>>>> different
>>>>>>> image files?
>>>>>>>
>>>>>>> For eg:
>>>>>>>
>>>>>>> 1) test
>>>>>>> 2) example
>>>>>>>
>>>>>>>
>>>>>>> I want "1) test" to go to a separate image file and " 2) example" to
>>>>>>> be
>>>>>>> saved into a different image file.
>>>>>>>
>>>>>>>
>>>>>>> Thanks in advance. Any help is appreciated.
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>>>>> For additional commands, e-mail: user-help@poi.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>>> For additional commands, e-mail: user-help@poi.apache.org
>>>>
>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by "Karthik.Gopalakrishnan" <kp...@uky.edu>.
I mean, it(the example for the bullet list) works fine if i try to create a
power point slide but i want to draw the TextBox shape into a jpeg image
directly.
Karthik.Gopalakrishnan wrote:
>
> Thanks for ur quick reply.
>
> I tried that too, i get a different Null pointer exception(below):-(
>
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.poi.hslf.model.TextRun.getTextRuler(TextRun.java:672)
> at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:128)
> at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
> at ReadPPT.test2(ReadPPT.java:311)
> at test.main(test.java:14)
>
>
>
>
> Yegor Kozlov wrote:
>>
>>
>> Call slide.addShape(textBox) first. It should help.
>>
>> Yegor
>>
>>> I dont think its a bug , i am missing something really preliminary
>>>
>>> This is the portion of the code i was trying to run( yes , its from the
>>> example on the POI page to create text with bullets)
>>>
>>> TextBox shape1 = new TextBox();
>>> shape1.setText("January\r" + "February\r" + "March\r"
>>> + "April");
>>> RichTextRun rt = shape1.getTextRun().getRichTextRuns()[0];
>>> rt.setFontSize(42);
>>> rt.setBullet(true);
>>> rt.setBulletOffset(0);
>>> rt.setTextOffset(50);
>>> rt.setBulletChar('\u263A');
>>> shape1.setAnchor(anchor);
>>> shape1.draw(graphics);
>>>
>>>
>>> Exception i get is
>>>
>>> Exception in thread "main" java.lang.NullPointerException
>>> at
>>> org.apache.poi.hslf.usermodel.RichTextRun.getCharTextPropVal(RichTextRun.java:287)
>>> at
>>> org.apache.poi.hslf.usermodel.RichTextRun.getFontColor(RichTextRun.java:518)
>>> at
>>> org.apache.poi.hslf.model.TextPainter.getAttributedString(TextPainter.java:76)
>>> at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:98)
>>> at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
>>> at ReadPPT.test2(ReadPPT.java:312)
>>> at test.main(test.java:14)
>>>
>>>
>>> Thanks
>>>
>>> Karthik
>>>
>>>
>>> Yegor Kozlov wrote:
>>>>
>>>>> Is there a simple way to save a
>>>>> Textbox(org.apache.poi.hslf.model.TextBox)
>>>>> with such formatted text as an image?
>>>>>
>>>>> I see, it has a draw method but when i invoke that , i get
>>>>> NullPointerException. Does it look for any specific attribute to be
>>>>> set?
>>>>>
>>>> Post the stack trace.
>>>> If you think it is a bug, open an issue in bugzilla.
>>>>
>>>> Yegor
>>>>
>>>>>
>>>>> Yegor Kozlov wrote:
>>>>>> No, you can't save individual lines of text. However, you can save
>>>>>> each
>>>>>> shape in a separate image:
>>>>>>
>>>>>> for (Shape sh : slide.getShapes()){
>>>>>>
>>>>>> Rectangle anchor = sh.getAnchor();
>>>>>> BufferedImage img = new BufferedImage(anchor .width, anchor
>>>>>> .height,
>>>>>> BufferedImage.TYPE_INT_RGB);
>>>>>> Graphics2D graphics = img.createGraphics();
>>>>>> sh.draw(graphics);
>>>>>>
>>>>>> ....
>>>>>> }
>>>>>>
>>>>>> See the source code of org.apache.poi.hslf.model.TextPainter. You can
>>>>>> re-use some of its functionality and write custom
>>>>>> text renderer which would draw individual bullets and lines.
>>>>>>
>>>>>> Yegor
>>>>>>
>>>>>>> I am trying to get each slide and convert them into images. I was
>>>>>>> able
>>>>>>> to
>>>>>>> do
>>>>>>> this with the examples i found in
>>>>>>> http://poi.apache.org/hslf/how-to-shapes.html.
>>>>>>>
>>>>>>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>>>>>>> Is there a way i can save each of those lines(and the bullet) into
>>>>>>> different
>>>>>>> image files?
>>>>>>>
>>>>>>> For eg:
>>>>>>>
>>>>>>> 1) test
>>>>>>> 2) example
>>>>>>>
>>>>>>>
>>>>>>> I want "1) test" to go to a separate image file and " 2) example" to
>>>>>>> be
>>>>>>> saved into a different image file.
>>>>>>>
>>>>>>>
>>>>>>> Thanks in advance. Any help is appreciated.
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>>>>> For additional commands, e-mail: user-help@poi.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>>> For additional commands, e-mail: user-help@poi.apache.org
>>>>
>>>>
>>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19575032.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by "Karthik.Gopalakrishnan" <kp...@uky.edu>.
Thanks for ur quick reply.
I tried that too, i get a different Null pointer exception(below):-(
Exception in thread "main" java.lang.NullPointerException
at org.apache.poi.hslf.model.TextRun.getTextRuler(TextRun.java:672)
at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:128)
at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
at ReadPPT.test2(ReadPPT.java:311)
at test.main(test.java:14)
Yegor Kozlov wrote:
>
>
> Call slide.addShape(textBox) first. It should help.
>
> Yegor
>
>> I dont think its a bug , i am missing something really preliminary
>>
>> This is the portion of the code i was trying to run( yes , its from the
>> example on the POI page to create text with bullets)
>>
>> TextBox shape1 = new TextBox();
>> shape1.setText("January\r" + "February\r" + "March\r"
>> + "April");
>> RichTextRun rt = shape1.getTextRun().getRichTextRuns()[0];
>> rt.setFontSize(42);
>> rt.setBullet(true);
>> rt.setBulletOffset(0);
>> rt.setTextOffset(50);
>> rt.setBulletChar('\u263A');
>> shape1.setAnchor(anchor);
>> shape1.draw(graphics);
>>
>>
>> Exception i get is
>>
>> Exception in thread "main" java.lang.NullPointerException
>> at
>> org.apache.poi.hslf.usermodel.RichTextRun.getCharTextPropVal(RichTextRun.java:287)
>> at
>> org.apache.poi.hslf.usermodel.RichTextRun.getFontColor(RichTextRun.java:518)
>> at
>> org.apache.poi.hslf.model.TextPainter.getAttributedString(TextPainter.java:76)
>> at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:98)
>> at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
>> at ReadPPT.test2(ReadPPT.java:312)
>> at test.main(test.java:14)
>>
>>
>> Thanks
>>
>> Karthik
>>
>>
>> Yegor Kozlov wrote:
>>>
>>>> Is there a simple way to save a
>>>> Textbox(org.apache.poi.hslf.model.TextBox)
>>>> with such formatted text as an image?
>>>>
>>>> I see, it has a draw method but when i invoke that , i get
>>>> NullPointerException. Does it look for any specific attribute to be
>>>> set?
>>>>
>>> Post the stack trace.
>>> If you think it is a bug, open an issue in bugzilla.
>>>
>>> Yegor
>>>
>>>>
>>>> Yegor Kozlov wrote:
>>>>> No, you can't save individual lines of text. However, you can save
>>>>> each
>>>>> shape in a separate image:
>>>>>
>>>>> for (Shape sh : slide.getShapes()){
>>>>>
>>>>> Rectangle anchor = sh.getAnchor();
>>>>> BufferedImage img = new BufferedImage(anchor .width, anchor
>>>>> .height,
>>>>> BufferedImage.TYPE_INT_RGB);
>>>>> Graphics2D graphics = img.createGraphics();
>>>>> sh.draw(graphics);
>>>>>
>>>>> ....
>>>>> }
>>>>>
>>>>> See the source code of org.apache.poi.hslf.model.TextPainter. You can
>>>>> re-use some of its functionality and write custom
>>>>> text renderer which would draw individual bullets and lines.
>>>>>
>>>>> Yegor
>>>>>
>>>>>> I am trying to get each slide and convert them into images. I was
>>>>>> able
>>>>>> to
>>>>>> do
>>>>>> this with the examples i found in
>>>>>> http://poi.apache.org/hslf/how-to-shapes.html.
>>>>>>
>>>>>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>>>>>> Is there a way i can save each of those lines(and the bullet) into
>>>>>> different
>>>>>> image files?
>>>>>>
>>>>>> For eg:
>>>>>>
>>>>>> 1) test
>>>>>> 2) example
>>>>>>
>>>>>>
>>>>>> I want "1) test" to go to a separate image file and " 2) example" to
>>>>>> be
>>>>>> saved into a different image file.
>>>>>>
>>>>>>
>>>>>> Thanks in advance. Any help is appreciated.
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>>>> For additional commands, e-mail: user-help@poi.apache.org
>>>>>
>>>>>
>>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19575010.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by Yegor Kozlov <ye...@dinom.ru>.
Call slide.addShape(textBox) first. It should help.
Yegor
> I dont think its a bug , i am missing something really preliminary
>
> This is the portion of the code i was trying to run( yes , its from the
> example on the POI page to create text with bullets)
>
> TextBox shape1 = new TextBox();
> shape1.setText("January\r" + "February\r" + "March\r"
> + "April");
> RichTextRun rt = shape1.getTextRun().getRichTextRuns()[0];
> rt.setFontSize(42);
> rt.setBullet(true);
> rt.setBulletOffset(0);
> rt.setTextOffset(50);
> rt.setBulletChar('\u263A');
> shape1.setAnchor(anchor);
> shape1.draw(graphics);
>
>
> Exception i get is
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.apache.poi.hslf.usermodel.RichTextRun.getCharTextPropVal(RichTextRun.java:287)
> at
> org.apache.poi.hslf.usermodel.RichTextRun.getFontColor(RichTextRun.java:518)
> at
> org.apache.poi.hslf.model.TextPainter.getAttributedString(TextPainter.java:76)
> at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:98)
> at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
> at ReadPPT.test2(ReadPPT.java:312)
> at test.main(test.java:14)
>
>
> Thanks
>
> Karthik
>
>
> Yegor Kozlov wrote:
>>
>>> Is there a simple way to save a
>>> Textbox(org.apache.poi.hslf.model.TextBox)
>>> with such formatted text as an image?
>>>
>>> I see, it has a draw method but when i invoke that , i get
>>> NullPointerException. Does it look for any specific attribute to be set?
>>>
>> Post the stack trace.
>> If you think it is a bug, open an issue in bugzilla.
>>
>> Yegor
>>
>>>
>>> Yegor Kozlov wrote:
>>>> No, you can't save individual lines of text. However, you can save each
>>>> shape in a separate image:
>>>>
>>>> for (Shape sh : slide.getShapes()){
>>>>
>>>> Rectangle anchor = sh.getAnchor();
>>>> BufferedImage img = new BufferedImage(anchor .width, anchor .height,
>>>> BufferedImage.TYPE_INT_RGB);
>>>> Graphics2D graphics = img.createGraphics();
>>>> sh.draw(graphics);
>>>>
>>>> ....
>>>> }
>>>>
>>>> See the source code of org.apache.poi.hslf.model.TextPainter. You can
>>>> re-use some of its functionality and write custom
>>>> text renderer which would draw individual bullets and lines.
>>>>
>>>> Yegor
>>>>
>>>>> I am trying to get each slide and convert them into images. I was able
>>>>> to
>>>>> do
>>>>> this with the examples i found in
>>>>> http://poi.apache.org/hslf/how-to-shapes.html.
>>>>>
>>>>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>>>>> Is there a way i can save each of those lines(and the bullet) into
>>>>> different
>>>>> image files?
>>>>>
>>>>> For eg:
>>>>>
>>>>> 1) test
>>>>> 2) example
>>>>>
>>>>>
>>>>> I want "1) test" to go to a separate image file and " 2) example" to be
>>>>> saved into a different image file.
>>>>>
>>>>>
>>>>> Thanks in advance. Any help is appreciated.
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>>> For additional commands, e-mail: user-help@poi.apache.org
>>>>
>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by "Karthik.Gopalakrishnan" <kp...@uky.edu>.
I dont think its a bug , i am missing something really preliminary
This is the portion of the code i was trying to run( yes , its from the
example on the POI page to create text with bullets)
TextBox shape1 = new TextBox();
shape1.setText("January\r" + "February\r" + "March\r"
+ "April");
RichTextRun rt = shape1.getTextRun().getRichTextRuns()[0];
rt.setFontSize(42);
rt.setBullet(true);
rt.setBulletOffset(0);
rt.setTextOffset(50);
rt.setBulletChar('\u263A');
shape1.setAnchor(anchor);
shape1.draw(graphics);
Exception i get is
Exception in thread "main" java.lang.NullPointerException
at
org.apache.poi.hslf.usermodel.RichTextRun.getCharTextPropVal(RichTextRun.java:287)
at
org.apache.poi.hslf.usermodel.RichTextRun.getFontColor(RichTextRun.java:518)
at
org.apache.poi.hslf.model.TextPainter.getAttributedString(TextPainter.java:76)
at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:98)
at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:532)
at ReadPPT.test2(ReadPPT.java:312)
at test.main(test.java:14)
Thanks
Karthik
Yegor Kozlov wrote:
>
>
>> Is there a simple way to save a
>> Textbox(org.apache.poi.hslf.model.TextBox)
>> with such formatted text as an image?
>>
>> I see, it has a draw method but when i invoke that , i get
>> NullPointerException. Does it look for any specific attribute to be set?
>>
>
> Post the stack trace.
> If you think it is a bug, open an issue in bugzilla.
>
> Yegor
>
>>
>>
>> Yegor Kozlov wrote:
>>> No, you can't save individual lines of text. However, you can save each
>>> shape in a separate image:
>>>
>>> for (Shape sh : slide.getShapes()){
>>>
>>> Rectangle anchor = sh.getAnchor();
>>> BufferedImage img = new BufferedImage(anchor .width, anchor .height,
>>> BufferedImage.TYPE_INT_RGB);
>>> Graphics2D graphics = img.createGraphics();
>>> sh.draw(graphics);
>>>
>>> ....
>>> }
>>>
>>> See the source code of org.apache.poi.hslf.model.TextPainter. You can
>>> re-use some of its functionality and write custom
>>> text renderer which would draw individual bullets and lines.
>>>
>>> Yegor
>>>
>>>> I am trying to get each slide and convert them into images. I was able
>>>> to
>>>> do
>>>> this with the examples i found in
>>>> http://poi.apache.org/hslf/how-to-shapes.html.
>>>>
>>>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>>>> Is there a way i can save each of those lines(and the bullet) into
>>>> different
>>>> image files?
>>>>
>>>> For eg:
>>>>
>>>> 1) test
>>>> 2) example
>>>>
>>>>
>>>> I want "1) test" to go to a separate image file and " 2) example" to be
>>>> saved into a different image file.
>>>>
>>>>
>>>> Thanks in advance. Any help is appreciated.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19574494.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by Yegor Kozlov <ye...@dinom.ru>.
> Is there a simple way to save a Textbox(org.apache.poi.hslf.model.TextBox)
> with such formatted text as an image?
>
> I see, it has a draw method but when i invoke that , i get
> NullPointerException. Does it look for any specific attribute to be set?
>
Post the stack trace.
If you think it is a bug, open an issue in bugzilla.
Yegor
>
>
> Yegor Kozlov wrote:
>> No, you can't save individual lines of text. However, you can save each
>> shape in a separate image:
>>
>> for (Shape sh : slide.getShapes()){
>>
>> Rectangle anchor = sh.getAnchor();
>> BufferedImage img = new BufferedImage(anchor .width, anchor .height,
>> BufferedImage.TYPE_INT_RGB);
>> Graphics2D graphics = img.createGraphics();
>> sh.draw(graphics);
>>
>> ....
>> }
>>
>> See the source code of org.apache.poi.hslf.model.TextPainter. You can
>> re-use some of its functionality and write custom
>> text renderer which would draw individual bullets and lines.
>>
>> Yegor
>>
>>> I am trying to get each slide and convert them into images. I was able to
>>> do
>>> this with the examples i found in
>>> http://poi.apache.org/hslf/how-to-shapes.html.
>>>
>>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>>> Is there a way i can save each of those lines(and the bullet) into
>>> different
>>> image files?
>>>
>>> For eg:
>>>
>>> 1) test
>>> 2) example
>>>
>>>
>>> I want "1) test" to go to a separate image file and " 2) example" to be
>>> saved into a different image file.
>>>
>>>
>>> Thanks in advance. Any help is appreciated.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by "Karthik.Gopalakrishnan" <kp...@uky.edu>.
Is there a simple way to save a Textbox(org.apache.poi.hslf.model.TextBox)
with such formatted text as an image?
I see, it has a draw method but when i invoke that , i get
NullPointerException. Does it look for any specific attribute to be set?
Yegor Kozlov wrote:
>
> No, you can't save individual lines of text. However, you can save each
> shape in a separate image:
>
> for (Shape sh : slide.getShapes()){
>
> Rectangle anchor = sh.getAnchor();
> BufferedImage img = new BufferedImage(anchor .width, anchor .height,
> BufferedImage.TYPE_INT_RGB);
> Graphics2D graphics = img.createGraphics();
> sh.draw(graphics);
>
> ....
> }
>
> See the source code of org.apache.poi.hslf.model.TextPainter. You can
> re-use some of its functionality and write custom
> text renderer which would draw individual bullets and lines.
>
> Yegor
>
>> I am trying to get each slide and convert them into images. I was able to
>> do
>> this with the examples i found in
>> http://poi.apache.org/hslf/how-to-shapes.html.
>>
>> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
>> Is there a way i can save each of those lines(and the bullet) into
>> different
>> image files?
>>
>> For eg:
>>
>> 1) test
>> 2) example
>>
>>
>> I want "1) test" to go to a separate image file and " 2) example" to be
>> saved into a different image file.
>>
>>
>> Thanks in advance. Any help is appreciated.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Using-POI-for-ppt-to-image-conversion-tp19555971p19574200.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Using POI for ppt to image conversion
Posted by Yegor Kozlov <ye...@dinom.ru>.
No, you can't save individual lines of text. However, you can save each shape in a separate image:
for (Shape sh : slide.getShapes()){
Rectangle anchor = sh.getAnchor();
BufferedImage img = new BufferedImage(anchor .width, anchor .height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
sh.draw(graphics);
....
}
See the source code of org.apache.poi.hslf.model.TextPainter. You can re-use some of its functionality and write custom
text renderer which would draw individual bullets and lines.
Yegor
> I am trying to get each slide and convert them into images. I was able to do
> this with the examples i found in
> http://poi.apache.org/hslf/how-to-shapes.html.
>
> Suppose my slide has 2 lines of text with bullets.(so 2 bullets)
> Is there a way i can save each of those lines(and the bullet) into different
> image files?
>
> For eg:
>
> 1) test
> 2) example
>
>
> I want "1) test" to go to a separate image file and " 2) example" to be
> saved into a different image file.
>
>
> Thanks in advance. Any help is appreciated.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org