|
View:
New views
18 Messages
—
Rating Filter:
Alert me
|
|
|
Generating ppt through javaI am trying to generate ppt through Java using Apache POI API. I am able to create table, bulletted text etc using this API.
Please answer the following two questions, if anyone aware of this. 1. How to split text across two slides, if the row had to be broken across 2 slides because the row is so big that it can only be accomodated in 2 slide ? 2. How to resize table cell , if the text which is going to put in that cell is larger than table cell size ? 3. Suppose I have some data and I want to put into some table cell, then how to calculate the table cell size (i.e. height or width) required. If the text is to be bold or font need to be changed then how to calculate the new height and width of the table cell ? |
|
|
Re: Generating ppt through java>
> 1. How to split text across two slides, if the row had to be broken across > 2 slides because the row is so big that it can only be accomodated in 2 > slide ? It is up to your application. Broke text into paragraphs and put each one in a separate slide. > > 2. How to resize table cell , if the text which is going to put in that cell > is larger than table cell size ? > > Use Table.setColumnWidth and Table.setRowHeight to control cell size. http://poi.apache.org/hslf/how-to-shapes.html#Tables Yegor --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Generating ppt through javaThanks for the reply.
Suppose I have some data and I want to put into some table cell, then how to calculate the table cell size (i.e. height or width) required. If the text is to be bold or font need to be changed then how to calculate the new height and width of the table cell ?
|
|
|
Re: Generating ppt through javaHi,
suppose I have some 9 rows of text. How can we find that only these many rows can be put into one slide and remaining can be put into another slide. i.e. How can we calculate that one slide can hold this much text. How can we calculate in the below cases ? 1. if we change font and make it bold etc) ? 2. if the alignment of the text is changed ?
|
|
|
Re: Generating ppt through java> Thanks for the reply. > > Suppose I have some data and I want to put into some table cell, then how to > calculate the table cell size (i.e. height or width) required. If the text > is to be bold or font need to be changed then how to calculate the new > height and width of the table cell ? For a standalone text shape you can call TextShape.resizeToFitText() but it won't work for tables. Currently HSLF does not provide the requested functionality. In theory you can calculate text dimensions using Java2D but in general case it's not a trivial task. You will have to take into account spacing between lines, spacing before and after paragraphs, tabs, text rulers, etc. Looking at the source code of org.apache.poi.hslf.model.TextPainter might give an idea how to do that. Yegor > > > > > > > dinshetty wrote: >> I am trying to generate ppt through Java using Apache POI API. I am able >> to create table, bulletted text etc using this API. >> >> Please answer the following two questions, if anyone aware of this. >> >> 1. How to split text across two slides, if the row had to be broken >> across 2 slides because the row is so big that it can only be accomodated >> in 2 slide ? >> >> 2. How to resize table cell , if the text which is going to put in that >> cell is larger than table cell size ? >> 3. Suppose I have some data and I want to put into some table cell, then >> how to calculate the table cell size (i.e. height or width) required. If >> the text is to be bold or font need to be changed then how to calculate >> the new height and width of the table cell ? >> > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Generating ppt through javaHi,
Pls explain why TextRun and RichTextRun are used what does it represent. |
|
|
Re: Generating ppt through javaHi Yegor,
Could you pls explain me how to find out how to find out the width and height of a character (with some style, font, bold, underlined etc) in a PPT ? Regards, Dinakara
|
|
|
Re: Generating ppt through javaDimension of an individual character can be calculated using java.awt.Font.getStringBounds .
Example: FontRenderContext frc= new FontRenderContext(null, true, true); Font font = new Font("Arial", Font.ITALIC | Font.BOLD, 10); Rectangle2D bounds = font.getStringBounds("POI", frc); If you have a text with multiple style runs then you will need to use java.text.AttributedString. You can leverage TextPainter.getAttributedString, this method iterates over RichTextRuns in the TextRun and builds AttributedString for you. Suppose you set the width of a text box to 200px and want to calculate the number of lines and total height of the text. The code below demonstrates how you can do that: TextShape textShape = ...; TextPainter paineter = new TextPainter(textShape); AttributedString str = paineter.getAttributedString(textShape.getTextRun()); AttributedCharacterIterator text = str.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(text, frc); float wrappingWidth = (float)textShape.getAnchor2D().getWidth(); float textHeight = 0; while (measurer.getPosition() < text.getEndIndex()) { TextLayout layout = measurer.nextLayout(wrappingWidth); textHeight += layout.getAscent() + layout.getDescent() + layout.getLeading(); } System.out.println(" wrapping width: " + wrappingWidth + ", text height: " + textHeight); Note, the calculation above is very rough and doesn't take into account margins, line spacings, etc. For a more complete example see how TextPainter draws text. Yegor > Hi Yegor, > > Could you pls explain me how to find out how to find out the width and > height of a character (with some style, font, bold, underlined etc) in a > PPT ? > > Regards, > Dinakara > > > dinshetty wrote: >> Hi, >> >> Pls explain why TextRun and RichTextRun are used what does it represent. >> > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Generating ppt through javaHi Yegor,
I tried to run the follwing code, But I am getting some null pointer exception as below _records in TextRun.java is null. Why is this _records is used for? What can be done to resolve this ? Exception: Exception in thread "main" java.lang.NullPointerException at org.apache.poi.hslf.model.TextRun.getTextRuler(TextRun.java:671) at org.apache.poi.hslf.model.TextPainter.paint(TextPainter.java:128) at org.apache.poi.hslf.model.TextShape.draw(TextShape.java:531) at org.apache.poi.hslf.examples.TextPainter_small.main(TextPainter_small.java:57) Program SlideShow ppt = new SlideShow(); ppt.setPageSize(new Dimension(720, 540)); Slide slide = ppt.createSlide(); ShapeGroup group = new ShapeGroup(); //define position of the drawing in the slide Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300); group.setAnchor(bounds); slide.addShape(group); TextBox box1 = new TextBox(); group.setCoordinates(new java.awt.Rectangle(0, 0, 100, 100)); group.addShape(box1); Graphics2D graphics = new PPGraphics2D(group); TextRun tr1 = box1.createTextRun(); tr1.getRichTextRuns()[0].setFontSize(12); tr1.getRichTextRuns()[0].setFontName("Arial"); box1.setHorizontalAlignment(TextBox.AlignLeft); tr1.setText( "Yegor Kozlov\r" + "yegor - apache - org\r" + "yegor - apache - org\r" + "yegor - apache - org"); /*TextPainter painter = new TextPainter(box1); painter.paint(graphics);*/ box1.draw(graphics); slide.addShape(box1); |
|
|
Re: Generating ppt through javaHi Yegor,
The following method in PPGrapics2D is not implemented in the latest source code in hslf. Whether it is going to be implemented shortly ? The method paint() in TextPainter class uses this method. Is there any alternate way to display the text if we have corresponding "AttributedCharacterIterator" and coordinates like below ? public void drawString(AttributedCharacterIterator iterator, float x, float y) { log.log(POILogger.WARN, "Not implemented"); } Regards, Dinakara |
|
|
Re: Generating ppt through java>
> The following method in PPGrapics2D is not implemented in the latest source > code in hslf. > Whether it is going to be implemented shortly ? The method paint() in > TextPainter class uses this method. > Is there any alternate way to display the text if we have corresponding > "AttributedCharacterIterator" and coordinates like below ? > > public void drawString(AttributedCharacterIterator iterator, float x, > float y) { > log.log(POILogger.WARN, "Not implemented"); > } > Are you trying to draw a ppt into another ppt? If so, it is a bad idea and the result will always be lossy. PPGrapics2D.drawString(AttributedCharacterIterator iterator, float x, float y) is indeed not implemented but I don't think you need to call it. TextPainter translates ppt into image. This class is meant to work with Graphics2D provided by AWT or by BufferedImage, for example, created as follows: BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); BufferedImage can draw attributed strings just fine. In it's turn, PPGrapics2D does a reverse job - it translates Grapics2D calls into ppt. This class is not fully compliant with the Graphics2D and some features like clipping, images and attributed strings are not yet supported. Example: http://poi.apache.org/hslf/how-to-shapes.html#Graphics2D Regards, Yegor --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Generating ppt through javaHi Yegor,
I could set color and font (bold, italic) in PPGraphics2D and was able to display it. However How to display underlined text using PPGraphics2D.drawString(String s,float x ,float y) ? Regards, Dinakara |
|
|
Re: Generating ppt through javaI Java2D advanced font properties (underline, strikethrough, etc.) are set via AttrtibutedString:
AttrtibutedString at = new AttrtibutedString("Hello, World"); at.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); graphics.drawString(at.getIterator(), float x, float y) Unfortunately, HSLF does not yet support this functionality. Yegor > Hi Yegor, > > I could set color and font (bold, italic) in PPGraphics2D and was able to > display it. > However How to display underlined text using PPGraphics2D.drawString(String > s,float x ,float y) ? > > > Regards, > Dinakara --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Generating ppt through javaHi Yegor,
Do you have any idea how to create PPT using XML ? Is there any API availbale for this ? (I heard that Power point 2007 supports this feature. is that true ?) Regards, Dinakara |
|
|
Re: Generating ppt through javaHi Yegor,
I created a Table using hslf API. when I tried to enter more text manually into the table cell (in the generated PPT) the row height used to get increased automatically. But once we set anchor for the table cells using "setAnchor" method of "table cell", the row height won't increase automatically when I try to enter text manually as mentioned above. It looks as if table cell height and width is fixed and it wont get increased. Actually I need to set the anchor for the table cells depending on the height of the text and also I need to allow the user to modify it manually once the ppt is generated. Can we set the anchor of the table cell and also at the same time can we allow the table cell to increase its height automatically once the user enters some more text into the table cell. Regards, Dinakara
|
|
|
Re: Generating ppt through javaYou should not set anchors of individual table cells. Instead use Table.setColumnWidth and Table.setRowHeight methods.
Table is a group of shapes which MUST conform to certain layout constraints. Once they are broken, the table may not be properly resized when the user enters text manually. Yegor > Hi Yegor, > > I created a Table using hslf API. when I tried to enter more text manually > into the table cell (in the generated PPT) the row height used to get > increased automatically. > But once we set anchor for the table cells using "setAnchor" method of > "table cell", > the row height won't increase automatically when I try to enter text > manually as mentioned above. It looks as if table cell height and width is > fixed and it wont get increased. > > Actually I need to set the anchor for the table cells depending on the > height of the text and also I > need to allow the user to modify it manually once the ppt is generated. > Can we set the anchor of the table cell and also at the same time can we > allow the table cell to increase its height automatically once the user > enters some more text into the table cell. > > Regards, > Dinakara > > dinshetty wrote: >> Hi Yegor, >> >> Do you have any idea how to create PPT using XML ? >> Is there any API availbale for this ? >> (I heard that Power point 2007 supports this feature. is that true ?) >> >> Regards, >> Dinakara >> > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Generating ppt through javaHi Yegor,
How can we insert a new slide between two slides of an existing ppt ? Regards, Dinakara |
|
|
Re: Generating ppt through javaUse ppt.reorderSlide to change the order of slides.
You will need to take the recent changes from trunk. Yegor > Hi Yegor, > > How can we insert a new slide between two slides of an existing ppt ? > > Regards, > Dinakara --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
| Free Forum Powered by Nabble | Forum Help |