2

i am using apache poi hslf for ppt genertion. I want to write in text box like first line is heading and is bold, rest is content and non bold. I have used HSLFTextRun to keep the settings different for heading and content.I am facing issue that whenever i apply setbold(true) for heading text run. It also makes the content bold as well. although i have tried setting setbold(false) for the content but of no use. Following is the code

     public static void main(String[] args) throws IOException {
        HSLFSlideShow ppt = new HSLFSlideShow();
        HSLFSlide slide = ppt.createSlide();
        HSLFTextBox tb = slide.createTextBox();
        tb.setAnchor(new Rectangle(100, 100, 200, 200));

        HSLFTextRun titleTR = tb.appendText("Title", true);
        titleTR.setBold(true);

        HSLFTextRun bullet1TR = tb.appendText(" bullet1", true);
        bullet1TR.getTextParagraph().setBullet(true);
        bullet1TR.setBold(false);
        HSLFTextRun bullet2TR = tb.appendText(" bullet2", true);
        bullet2TR.getTextParagraph().setBullet(true);
        bullet2TR.setBold(false);
        FileOutputStream fos = new FileOutputStream("bullet.ppt");
        ppt.write(fos);
        fos.close();
            ppt.close();
}

Any help on this matter is appreciate, Thanks.

user3768904
  • 261
  • 3
  • 15
  • The code works for Libre Office, but not Office 16 ... I'm checking now, what the differences are between those TextRuns ... – kiwiwings Aug 26 '17 at 21:58

1 Answers1

0

For whatever reason, it works for me if you set the bold text in the end:

public static void main(String[] args) throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    HSLFSlide slide = ppt.createSlide();
    HSLFTextBox tb = slide.createTextBox();
    tb.setAnchor(new Rectangle(100, 100, 200, 200));

    HSLFTextRun titleTR = tb.appendText("Title", false);
    tb.appendText("\n", false);

    HSLFTextRun bullet1TR = tb.appendText(" bullet1", true);
    bullet1TR.getTextParagraph().setBullet(true);

    HSLFTextRun bullet2TR = tb.appendText(" bullet2", true);
    bullet2TR.getTextParagraph().setBullet(true);

    titleTR.setBold(true);

    FileOutputStream fos = new FileOutputStream("bullet.ppt");
    ppt.write(fos);
    fos.close();
    ppt.close();
}
JensS
  • 1,151
  • 2
  • 13
  • 20