> 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/uwp/get-started/samples/elementreadertest.md).

# ElementReader

Sample code for using Apryse UWP SDK to traverse the page display list using ElementReader.

Sample C# code for using Apryse SDK to traverse the page display list using ElementReader.

Learn more about our full [PDF Data Extraction SDK Capabilities](https://apryse.com/capabilities/extraction).

To start your free trial, [get stated with UWP SDK](/uwp/get-started/get-started.md).

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

```csharp
//
// Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
//

using System;
using System.IO;
using System.Threading.Tasks;
using Windows.Foundation;

using pdftron.PDF;
using pdftron.SDF;

using PDFNetUniversalSamples.ViewModels;

namespace PDFNetSamples
{
    public sealed class ElementReaderTest : Sample
    {
        public ElementReaderTest() :
            base("ElementReader", "Illustrates how to traverse page display list using ElementReader.")
        {
        }

        public override IAsyncAction RunAsync()
        {
            return Task.Run(new System.Action(() => {
                WriteLine("--------------------------------");
                WriteLine("Starting ElementReader Test...");
                WriteLine("--------------------------------\n");
                try {
                    WriteLine("-------------------------------------------------");
                    WriteLine("Extract text data from all pages in the document.");

                    // Open the test file
                    string input_file_path = Path.Combine(InputPath, "newsletter.pdf");
                    WriteLine("Opening input file: " + input_file_path);
                    PDFDoc doc = new PDFDoc(input_file_path);
                    doc.InitSecurityHandler();

                    PageIterator itr;
                    pdftron.PDF.ElementReader page_reader = new pdftron.PDF.ElementReader();

                    //int i = 0;
                    for (itr = doc.GetPageIterator(); itr.HasNext(); itr.Next())		//  Read every page
                    {
                        int pageNo = itr.GetPageNumber();
                        WriteLine(String.Format("Page {0:d} ----------------------------------------", pageNo));

                        page_reader.Begin(itr.Current());
                        String result = ProcessElements(page_reader);
                        WriteLine(result);
                        page_reader.End();
                    }
                    WriteLine("Done.");
                    doc.Destroy();
                }
                catch (Exception e) {
                    WriteLine(GetExceptionMessage(e));
                }

                WriteLine("\n--------------------------------");
                WriteLine("Done ElementReader Test.");
                WriteLine("--------------------------------\n");
            })).AsAsyncAction();
        }
        
        String ProcessElements(ElementReader reader)
        {
            String result = "";
            Element element;
            //int i = 0;
            while ((element = reader.Next()) != null) 	// Read page contents
            {
                switch (element.GetType())
                {
                    case ElementType.e_path:						// Process path data...
                        {
                            result += "Process Element.Type.e_path\n";
                            //PathData data = element.GetPathData();
                            //double[] points = data.get_pts();// points;
                            break;
                        }
                    case ElementType.e_image:                       // Process images...
                    case ElementType.e_inline_image:
                        {
                            result += "Process Element.Type.e_image\n";
                            break;
                        }
                    case ElementType.e_text: 				// Process text strings...
                        {
                            result += "Process Element.Type.e_text\n";
                            //String txt = element.GetTextString();
                            // Message+=(txt);
                            break;
                        }
                    case ElementType.e_form:				// Process form XObjects
                        {
                            result += "Process Element.Type.e_form\n";
                            reader.FormBegin();
                            result += ProcessElements(reader);
                            reader.End();
                            break;
                        }
                }
            }
            return result;
        }
    }
}
```

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


---

# 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/uwp/get-started/samples/elementreadertest.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.
