1

I am using apache poi xslf to create a text box and then adding a bullet point in it. Issue is that When bullet point is multi line text, it adds like this

-Text analysis, nGram, Naïve Bayes Text Classifier to identify the nature of the conversation, sentiment and risk of complaint being made

in above bullet point conversation should be aligned with word Text in bullet line i.e. text alignment like this

  • Text analysis, nGram, Naïve Bayes Text Classifier to identify the nature of
    the conversation sentiment and risk of complaint being made.

Following is the code

XSLFTextBox textbox = this.slide.createTextBox(); 
textbox.setAnchor(new Rectangle(this.xAxis,this.yAxis,this.width,this.height));  XSLFTextParagraph contentPara = textbox.addNewTextParagraph(); 
XSLFTextRun bullet1TR = contentPara.addNewTextRun();      contentPara.setBullet(true);  
contentPara.setFontAlign(FontAlign.TOP); contentPara.setTextAlign(TextAlign.LEFT);

Any help is appreciated. Thanks.

user3768904
  • 261
  • 3
  • 15
  • "Any help is appreciated.": Really? Because after I had helping you, then I not get any feedback from you. This seems not to be apprecation at all. – Axel Richter Nov 27 '17 at 04:44
  • sorry, i just checked the answer and tried it and it is working as expected. Thanks alot :) I have marked your answer as correct one as well. Thanks a lot! – user3768904 Nov 27 '17 at 08:45

1 Answers1

3

At first the whole paragraph needs left indented as much as the bullet point shall have space. Then the first row needs to have a hanging indent of the same width, so the first row, which has the bullet point in it, is not indented in sum.

Example:

import java.io.FileOutputStream;

import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.*;

import java.awt.Rectangle;

public class CreatePPTXTextBoxBullet {

 public static void main(String[] args) throws Exception {

  XMLSlideShow slideShow = new XMLSlideShow();

  XSLFSlide slide = slideShow.createSlide();

  XSLFTextBox textbox = slide.createTextBox(); 
  textbox.setAnchor(new Rectangle(50, 100, 570, 100));
  XSLFTextParagraph paragraph = textbox.addNewTextParagraph(); 
  paragraph.setBullet(true);
  paragraph.setLeftMargin(25.2); //left margin = indent for the text; 25.2 pt = 25.2/72 = 0.35"
  paragraph.setIndent(-25.2);  //hanging indent first row for the bullet point; -25.2 pt, so first row indent is 0.00 in sum
  paragraph.setFontAlign(TextParagraph.FontAlign.TOP);
  paragraph.setTextAlign(TextParagraph.TextAlign.LEFT);
  XSLFTextRun run = paragraph.addNewTextRun();
  run.setText("Text analysis, nGram, Naïve Bayes Text Classifier to identify the nature of the conversation, sentiment and risk of complaint being made");

  FileOutputStream out = new FileOutputStream("CreatePPTXTextBoxBullet.pptx");
  slideShow.write(out);
  out.close();
 }
}
Axel Richter
  • 56,077
  • 6
  • 60
  • 87