> 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/ios/editing-page-content/read.md).

# Reading page content on iOS

Learn how to read page content from a PDF document with full code samples. Traverse page display lists using ElementReader for SEO optimization. Understand Form XObjects, Type3 font glyphs, and tiling

To read page content from a document.

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTElementReader *reader = [[PTElementReader alloc] init];

for (PageIterator *itr=[doc GetPageIterator: 1]; [itr HasNext]; [itr Next])
{
  // Read the page
  [reader Begin: [itr Current]];
  ProcessElements(reader);
  [reader End];
}

void ProcessElements(PTElementReader *reader)
{
  // Traverse the page display list
  PTElement *element;	
  while ((element = [reader Next]))
  {
    switch ([element GetType])
    {	
      case e_ptpath:
      {
        if ([element IsClippingPath])
        {}
        // ...
        break;
      }
      case e_pttext_obj:
      {
        PTMatrix2D *text_mtx = [element GetTextMatrix];
        // ...
        break;
      }
      case e_ptform:
      {
        [reader FormBegin];
        ProcessElements(reader);
        [reader End];
        break;
      } 
    }
  }
}
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let reader: PTElementReader = PTElementReader()

let itr: PTPageIterator = doc.getPageIterator(1)
while itr.hasNext()
{
  // Read the page
  reader.begin(itr.current())
  ProcessElements(reader)
  reader.end()
  itr.next()
}

func ProcessElements(reader: PTElementReader)
{
  // Traverse the page display list
  while let element = reader.next()
  {
    switch element.getType()
    {
      case e_ptpath:
        if (element.isClippingPath())
        {}
        // ...
      case e_pttext_obj:
        PTMatrix2D text_mtx = element.getTextMatrix()
        // ...
      default:
        reader.formBegin()
        ProcessElements(reader)
        reader.end()
    }
  }
}
```

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

[Read Elements Across All PDF Pages](/ios/get-started/samples.md#elementreader) Full code sample which illustrates how to traverse page display list using ElementReader.

## About reading page content

Page content is represented as a sequence of graphical Elements such as paths, text, images, and forms. The only effect of the ordering of Elements in the display list is the order in which Elements are painted. Elements that occur later in the display list can obscure earlier elements.

A display list can be traversed using an ElementReader object. To start traversing the display list, call `reader.Begin()`. Then, `reader.Next()` will return subsequent Elements until null is returned (marking the end of the display list). While ElementReader only works with one page at a time, the same ElementReader object may be reused to process multiple pages.

## About Form XObjects, Type3 font glyphs, and tiling patterns

A PDF page display list may contain child display lists of Form XObjects, Type3 font glyphs, and tiling patterns. A form XObject is a self-contained description of any sequence of graphics objects (such as path objects, text objects, and sampled images), defined as a PDF content stream. It may be painted multiple times — either on several pages or at several locations on the same page — and will produce the same results each time (subject only to the graphics state at the time the Form XObject is painted). In order to open a child display list for a Form XObject, call the `reader.FormBegin()` method. To return processing to the parent display list call `reader.End()`. Processing of the Form XObject display (traversing the child display list) is illustrated below.

![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-94e76e0c5230468a3885c42d678169a0134da55b%2Ff038ed3927d062c2f8107f3ed8f583cae53394f7-176x274.gif?alt=media)

Note that, in the above sample code, a child display list is opened when an element with type `Element.ElementType.e_form` is encountered by the `reader.FormBegin()` method. The child display list becomes the current display list until it is closed using `reader.End()`. At this point the processing is returned to the parent display list and the next Element returned will be the Element following the Form XObject. Also note that, because Form XObjects may be nested, a sub-display list could have its own child display lists. The sample above shows traversing these nested Form XObjects recursively.

Similarly, a pattern display list can be opened using `reader.PatternBegin()`, and a Type3 glyph display list can be opened using the `reader.Type3FontBegin()` method.


---

# 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/ios/editing-page-content/read.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.
