Hello POI Team, I am working on reporting requirement, where in slides are generated dynamically from a simple template of size 16:9, template has two places holders, a table with multiple rows and a fixed size text box (6.2" x 9.75"), the size of the text box should not exceed predefined size in template, its sized to align perfectly into the slide. The text that goes into text box on PPT is text keyed in by user in application via Reach Text Editor - RTE field, supports standard RTE styling like BOLD, Italic, Underline, Strike through, order & un-ordered list and H1 to H3 headers with normal format, there is no limit on the text length. User has an option to download the content as PPT report, report has to retain the format/styling user has used. Now coming to problem, when the text keyed in by user runs longer than text that can fit into text box on the slide text overflows, when there is text overflow a new slide has to be created with a text box for overflow text. No shrink of text on overflow. I checked XSLFTextShape.getTextHeight() to get text height, the endpoint returns text height based on the font style etc. As text keyed-in is via RTE, styling can vary, figuring out what text can fit into text box considering the varying text font ex: a lengthy text with normal styling can fit into text box, but when user apply H1 Style or add an ordered list on same text will result in overflow. User is free to apply all supporting styling in RTE. Problem is I am not able to figure out the point of text overflow. Is there a possibility to programmatically via poi to know the point of overflow and act accordingly..? POI Version 4.0.1 Thanks Praveen -- Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
> I checked XSLFTextShape.getTextHeight() to get text height ...
> Problem is I am not able to figure out the point of text > overflow. I know about the inaccuracy of the getTextHeight(graphics2d) method, which varies from Windows/Linux/Mac system and the way Java vs. Windows-GDI renders fonts. You can test the height calculation of various RTF stylings by rendering the PNG via PPTX2PNG and check it against the output of Powerpoint. If the result satisfies you *), then you are able to figure out of the point of text overflow, which occurs when getTextHeight() is longer than your original textbox ... what exactly confuses you when you compare those two values? *) If the result doesn't satisfy you, then you need to dig into the SL Common drawing classes, and optimize the text rendering to your runtime environment and used fonts, which you probably don't know beforehand ... Andi |
kiwiwings wrote
> If the result satisfies you *), then you are able to figure out of the > point of text overflow, which occurs when getTextHeight() is longer than > your original textbox ... * > what exactly confuses you when you compare those two values? * On parsing through each RTE element, XSLFTextRun is added to XSLFTextParagraph, calling getTextHeight will return text height on adding each element, but I dont see any method in XSLFTextShape to know the original height of the text box which I can compare against to figure out the point of overflow. -- Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
the original height of the text box is the anchor height.but I dont see any method in XSLFTextShape to know the original height of the text box
here is an example, which stops (usually) when the textbox is
full. public void overflow() throws Exception { boolean useXml = false; try (SlideShow ppt = (useXml ? new XMLSlideShow() : new HSLFSlideShow())) { // intialize Slide slide = ppt.createSlide(); TextBox box = slide.createTextBox(); box.setAnchor(new Rectangle2D.Double(100,100,300,300)); box.setStrokeStyle(Color.RED); box.setInsets(new Insets2D(0,0,0,0)); // Compare height final double maxHeight = box.getAnchor().getHeight(); // randomize Random rnd = new Random(); double textHeight = 0; while (textHeight < maxHeight) { TextRun tr = box.appendText("blub ", textHeight > 0 && rnd.nextBoolean()); for (int i=rnd.nextInt(5); i>0; i--) { switch (rnd.nextInt(5)) { case 0: tr.setFontSize(2. + rnd.nextInt(20)); break; case 1: tr.setBold(rnd.nextBoolean()); break; case 2: tr.setFontColor(new Color(rnd.nextInt(0xFFFFFF))); break; case 3: tr.setUnderlined(rnd.nextBoolean()); break; case 4: tr.setFontFamily(rnd.nextBoolean() ? "Arial" : "Courier New"); break; } } textHeight = box.getTextHeight(); } try (FileOutputStream fos = new FileOutputStream("blub.ppt"+(useXml?"x":""))) { ppt.write(fos); } } } |
Thank you Andi! the code snippet really helps.
-- Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Free forum by Nabble | Edit this page |