import
java.io.*;
import
org.apache.poi.xslf.usermodel.*;
public
class
FormatTextPPT {
public
static
void
main(String args[])
throws
IOException
{
XMLSlideShow ppt =
new
XMLSlideShow();
XSLFSlideMaster slideMaster
= ppt.getSlideMasters().get(
0
);
XSLFSlideLayout slidelayout = slideMaster.getLayout(
SlideLayout.TITLE_AND_CONTENT);
XSLFSlide slide = ppt.createSlide(slidelayout);
XSLFTextShape title = slide.getPlaceholder(
1
);
title.clearText();
XSLFTextParagraph paragraph
= title.addNewTextParagraph();
XSLFTextRun line1 = paragraph.addNewTextRun();
line1.setText(
"Formatted Bold"
);
line1.setBold(
true
);
paragraph.addLineBreak();
XSLFTextRun line2 = paragraph.addNewTextRun();
line2.setText(
"Formatted with Color"
);
line2.setFontColor(java.awt.Color.RED);
line2.setFontSize(
24.0
);
paragraph.addLineBreak();
XSLFTextRun line3 = paragraph.addNewTextRun();
line3.setText(
"Formatted with Underline"
);
line3.setUnderlined(
true
);
line3.setFontColor(java.awt.Color.GRAY);
paragraph.addLineBreak();
XSLFTextRun line4 = paragraph.addNewTextRun();
line4.setText(
"Text Formatted with Strike"
);
line4.setFontSize(
12.0
);
line4.setItalic(
true
);
line4.setFontColor(java.awt.Color.BLUE);
line4.setStrikethrough(
true
);
line4.setFontSize(
24.0
);
paragraph.addLineBreak();
String path = System.getProperty(
"user.dir"
);
path +=
"/FormattedText.pptx"
;
File file =
new
File(path);
FileOutputStream out =
new
FileOutputStream(file);
ppt.write(out);
out.close();
ppt.close();
System.out.println(
"PPT with Formatted Text created successfully!"
);
}
}