> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/extraction/embedded-fonts.md).

# Embedded fonts in Android

Learn how to extract embedded fonts in a PDF document. Understand the importance of embedded fonts and how to access them using the Apryse SDK. Find examples and sample code for iterating over embedde

To extract embedded fonts in a document.

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
private boolean objIsEmbeddedFont(Obj indirectObj) {
  if (indirectObj.isFree()) {
    return false;
  }

  if (!indirectObj.isDict() && !indirectObj.isStream()) {
    return false;
  }

  Obj typeObj = indirectObj.findObj("Type");
  if (typeObj == null || !typeObj.isName()) {
    return false;
  }

  String typeName = typeObj.getName();
  if (!typeName.equals("Font")) {
    return false;
  }

  Obj subtypeObj = indirectObj.findObj("Subtype");
  if (subtypeObj != null && subtypeObj.isName()) {
    String subtypeName = subtypeObj.getName();
    if (subtypeName.equals("CIDFontType0")) {
      return false;
    }
  }

  Font font = new Font(indirectObj);
  return font.isEmbedded();
}

PDFDoc doc = new PDFDoc(filename);
SDFDoc sdfdoc = doc.getSDFDoc();
for(int i = 1; i < sdfdoc.xRefSize(); ++i) {
  Obj indirectObj = sdfdoc.getObj(i);
  if (objIsEmbeddedFont(indirectObj)) {
    // perform document processing
  }
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
fun objIsEmbeddedFont(indirectObj: Obj) : Boolean {
  if (indirectObj.isFree()) {
    return false
  }

  if (!indirectObj.isDict() && !indirectObj.isStream()) {
    return false
  }

  val typeObj = indirectObj.findObj("Type")
  if (typeObj == null || !typeObj.isName()) {
    return false
  }

  val typeName = typeObj.getName()
  if (!typeName.equals("Font")) {
    return false
  }

  val subtypeObj = indirectObj.findObj("Subtype")
  if (subtypeObj != null && subtypeObj.isName()) {
    val subtypeName = subtypeObj.getName()
    if (subtypeName.equals("CIDFontType0")) {
      return false
    }
  }

  val font = Font(indirectObj)
  return font.isEmbedded()
}

val doc = PDFDoc(filename)
val sdfdoc = doc.getSDFDoc()
for (i in 1 until sdfdoc.xRefSize()) {
  val indirectObj = sdfdoc.getObj(i);
  if (objIsEmbeddedFont(indirectObj)) {
    // perform document processing
  }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## About embedded fonts

PDF documents access fonts from one of two places: the host machine rendering the PDF document or from within the PDF document itself. When a font is used in a PDF document which is not available on the machine loading that document and it's not embedded within the document the viewer will usually load a different font. When that font is contained within the PDF document itself we call that an embedded font. When a PDF contains an embedded font that font can still be rendered even if it is not defined on the host machine.

All font information in a PDF is stored in the SDF layer as an SDF object and exists as either a dictionary or a stream. When a font exists a dictionary that means that means that it is defined exclusively within the PDF document but if it is defined as a stream that means it exists as a file which may or may not exist within the PDF document itself. It is possible for either type to be embedded.

![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-6bc3b982454c98f5eef6aea356b5dffde8b3afbf%2F014233a6db0bc5100093dd3c5265f5b9f97e6a91-537x260.gif?alt=media)

It's also possible to programatically embed fonts within a PDF with the Apryse SDK. You can find an example in the [ElementBuilder](/android/get-started/samples.md#elementbuilder) sample code.

The samples below demonstrates how to iterate over all embedded fonts found within a PDF document. Note that because this requires several low-level operations additional care must be taken for to check for possible null pointers. Also note that fonts with the subtype `CIDFontType0` are not not counted as embedded fonts because they are necessarily referenced by a parent font within the same document.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/android/extraction/embedded-fonts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
