There seems to be a font embedding possible in Microsoft Office documents. At least in PowerPoint and Word. See How to embed fonts in PowerPoint and How to embed a TrueType font in a document. But unfortunately apache poi
does not supporting storing this font files in /fonts/
part of the Office Open XML document files.
So using apache poi
until now the fonts used must be installed in the operating system. We only can give a string as the typeface
in XSLFTextRun.setFontFamily. If this font is installed in the operating system, then it will be used, else a similar font will be guessed if the file is rendered.
Example:
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.*;
import java.awt.Rectangle;
public class CreatePPTXTextBoxSpecialFont {
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();
XSLFTextRun run = paragraph.addNewTextRun();
run.setText("Arial ");
run.setFontFamily("Arial");
run.setFontSize(24d);
run = paragraph.addNewTextRun();
run.setText("Algerian ");
run.setFontFamily("Algerian");
run.setFontSize(24d);
run = paragraph.addNewTextRun();
run.setText("Courier ");
run.setFontFamily("Courier");
run.setFontSize(24d);
run = paragraph.addNewTextRun();
run.setText("Times New Roman ");
run.setFontFamily("Times New Roman");
run.setFontSize(24d);
FileOutputStream out = new FileOutputStream("CreatePPTXTextBoxSpecialFont.pptx");
slideShow.write(out);
out.close();
}
}
Result in PowerPoint Windows 10:

Result in Libreoffice Impress Ubuntu Linux:
