# Embed Fonts in Presentations Using PHP

> Embed TrueType fonts in PowerPoint and OpenDocument presentations with Aspose.Slides for PHP via Java, ensuring accurate rendering across all platforms.

Source: https://docs.aspose.com/slides/php-java/embedded-font/
Updated: 2026-08-02


## **Introduction**

**Embedded fonts in PowerPoint** are useful when you want your presentation to appear correctly when opened on any system or device. If you used a third-party or non-standard font because you got creative with your work, then you have even more reasons to embed your font. Otherwise (without embedded fonts), the texts or numbers on your slides, the layout, styling, etc. may change or turn into confusing rectangles. 

The [FontsManager](https://reference.aspose.com/slides/php-java/aspose.slides/FontsManager) class, [FontData](https://reference.aspose.com/slides/php-java/aspose.slides/fontdata/) class and [Compress](https://reference.aspose.com/slides/php-java/aspose.slides/compress/) class contain most of the methods you need to work with embedded fonts in PowerPoint presentations.

## **Get and Remove Embedded Fonts**

Aspose.Slides provides the [getEmbeddedFonts](https://reference.aspose.com/slides/php-java/aspose.slides/fontsmanager/#getEmbeddedFonts) method (exposed by the [FontsManager](https://reference.aspose.com/slides/php-java/aspose.slides/FontsManager) class) to allow you to get (or find out) the fonts embedded in a presentation. To remove fonts, the [removeEmbeddedFont](https://reference.aspose.com/slides/php-java/aspose.slides/fontsmanager/#removeEmbeddedFont) method (exposed by the same class) is used.

This PHP code shows you how to get and remove embedded fonts from a presentation:

```php
  # Instantiates a Presentation object that represents a presentation file
  $pres = new Presentation("EmbeddedFonts.pptx");
  try {
    # Renders a slide containing a text frame that uses embedded "FunSized"
    $slideImage = $pres->getSlides()->get_Item(0)->getImage(new Java("java.awt.Dimension", 960, 720));
    # Save the image to disk in JPEG format
    try {
      $slideImage->save("picture1_out.jpg", ImageFormat::Jpeg);
    } finally {
      if (!java_is_null($slideImage)) {
        $slideImage->dispose();
      }
    }
    $fontsManager = $pres->getFontsManager();
    # Gets all embedded fonts
    $embeddedFonts = $fontsManager->getEmbeddedFonts();
    # Finds the "Calibri" font
    $calibriEmbeddedFont = null;
    $Array = new java_class("java.lang.reflect.Array");
    for($i = 0; $i < java_values($Array->getLength($embeddedFonts)) ; $i++) {
      echo("" . $embeddedFonts[$i]->getFontName());
      if ("Calibri"->equals($embeddedFonts[$i]->getFontName())) {
        $calibriEmbeddedFont = $embeddedFonts[$i];
        break;
      }
    }
    # Removes "Calibri" font
    $fontsManager->removeEmbeddedFont($calibriEmbeddedFont);
    # Renders the presentation; "Calibri" font is replaced with an existing one
    $slideImage = $pres->getSlides()->get_Item(0)->getImage(new Java("java.awt.Dimension", 960, 720));
    # Save the image to disk in JPEG format
    try {
      $slideImage->save("picture2_out.jpg", ImageFormat::Jpeg);
    } finally {
      if (!java_is_null($slideImage)) {
        $slideImage->dispose();
      }
    }
    # Saves the presentation without embedded "Calibri" font to disk
    $pres->save("WithoutManageEmbeddedFonts_out.ppt", SaveFormat::Ppt);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }
```

## **Add Embedded Fonts**

Using the [EmbedFontCharacters](https://reference.aspose.com/slides/php-java/aspose.slides/embedfontcharacters/) class and two overloads of the [addEmbeddedFont](https://reference.aspose.com/slides/php-java/aspose.slides/fontsmanager/#addEmbeddedFont) method, you can select your preferred (embedding) rule to embed the fonts in a presentation. This PHP code shows you how to embed and add fonts to a presentation:

```php
  # Loads the presentation
  $pres = new Presentation("Fonts.pptx");
  try {
    $allFonts = $pres->getFontsManager()->getFonts();
    $embeddedFonts = $pres->getFontsManager()->getEmbeddedFonts();
    $Array = new java_class("java.lang.reflect.Array");
    foreach($allFonts as $font) {
      $embeddedFontsContainsFont = false;
      for($i = 0; $i < java_values($Array->getLength($embeddedFonts)) ; $i++) {
        if ($embeddedFonts[$i]->equals($font)) {
          $embeddedFontsContainsFont = true;
          break;
        }
      }
      if (!$embeddedFontsContainsFont) {
        $pres->getFontsManager()->addEmbeddedFont($font, EmbedFontCharacters->All);
        $embeddedFonts = $pres->getFontsManager()->getEmbeddedFonts();
      }
    }
    # Saves the presentation to disk
    $pres->save("AddEmbeddedFont_out.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }
```

## **Compress Embedded Fonts**

To allow you to compress the fonts embedded in a presentation and reduce its file size, Aspose.Slides provides the [compressEmbeddedFonts](https://reference.aspose.com/slides/php-java/aspose.slides/compress/#compressEmbeddedFonts) method (exposed by the [Compress](https://reference.aspose.com/slides/php-java/aspose.slides/compress/) class).

This PHP code shows you how to compress embedded PowerPoint fonts:

```php
  $pres = new Presentation("pres.pptx");
  try {
    Compress->compressEmbeddedFonts($pres);
    $pres->save("pres-out.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }
```

## **FAQ**

### How can I tell that a specific font in the presentation will still be substituted during rendering despite embedding?

Check the [substitution information](/slides/php-java/font-substitution/) in the font manager and the [fallback/substitution rules](/slides/php-java/fallback-font/): if the font is unavailable or restricted, a fallback will be used.

### Is it worth embedding "system" fonts like Arial/Calibri?

Usually no—they are almost always available. But for full portability in "thin" environments (Docker, a Linux server without preinstalled fonts), embedding system fonts can eliminate the risk of unexpected substitutions.

