> 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/elementedittest.md).

# ElementEdit

Here is a complete PDF and DOCX editing guide using C#. Modify properties, edit text, bookmarks,annotation and lot more using COS API

Sample C# code for using Apryse SDK to programmatically edit an existing PDF document's page display list and the graphics state attributes on existing elements. In particular, this sample strips all images from the page and changes the text color to blue. You can also build a GUI with [interactive PDF editor widgets](/uwp/get-started/samples.md#pdfview). Some of Apryse SDK's other functions for programmatically editing PDFs include the [Cos/SDF low-level API](/uwp/get-started/samples.md#sdf), [page manipulation](/uwp/get-started/samples.md#pdfpage), and more. Learn more about our [UWP SDK](/core/get-started/frameworks/dotnet.md) and [PDF Editing & Manipulation Library](/core/page-manipulation/manipulation.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 ElementEditTest : Sample
    {
        public ElementEditTest() :
            base("ElementEdit", "The sample code shows how to edit the page display list and how to modify graphics state attributes on existing Elements. In particular the sample program strips all images from the page and changes text color to blue.")
        {
        }

        public override IAsyncAction RunAsync()
        {
            return Task.Run(new System.Action(async () => {
                WriteLine("--------------------------------");
                WriteLine("Starting ElementEdit Test...");
                WriteLine("--------------------------------\n");

			    try
                {
                    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();

				    int num_pages = doc.GetPageCount();

                    PageIterator itr = doc.GetPageIterator();

				    ElementWriter writer = new ElementWriter();
				    ElementReader reader = new ElementReader();

                    while (itr.HasNext())
                    {
                        Page page = itr.Current();
				        reader.Begin(page);
					    writer.Begin(page, ElementWriterWriteMode.e_replacement, false);
					    ProcessElements(reader, writer);
					    writer.End();
					    reader.End();

                        itr.Next();
				    }
                    
                    String output_file_path = Path.Combine(OutputPath, "newsletter_edited.pdf");
                    await doc.SaveAsync(output_file_path, SDFDocSaveOptions.e_remove_unused);
				    doc.Destroy();
                    WriteLine("Done. Result saved in " + output_file_path);
                    await AddFileToOutputList(output_file_path).ConfigureAwait(false);
			    }
			    catch (Exception e)
			    {
				    WriteLine(GetExceptionMessage(e));
			    }

                WriteLine("\n--------------------------------");
                WriteLine("Done ElementEdit Test.");
                WriteLine("--------------------------------\n");
		    })).AsAsyncAction();
        }

		void ProcessElements(ElementReader reader, ElementWriter writer)
		{
			Element element;
			while ((element = reader.Next()) != null) 	// Read page contents
			{
				switch (element.GetType())
				{
					case ElementType.e_image:
					case ElementType.e_inline_image:
						// remove all images by skipping them
						continue;
                    case ElementType.e_path:				// Process path data...
                        {
                            // Set all paths to red color.
                            GState gs = element.GetGState();
                            gs.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
                            gs.SetFillColor(new ColorPt(1, 0, 0));
                            writer.WriteElement(element);
                            break;
                        }
					case ElementType.e_text: 				// Process text strings...
						{
							// Set all text to blue color.
							GState gs = element.GetGState();
							gs.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
							gs.SetFillColor(new ColorPt(0, 0, 1));
							writer.WriteElement(element);
							break;
						}
					case ElementType.e_form:				// Recursively process form XObjects
						{
							writer.WriteElement(element);

							reader.FormBegin();
							ElementWriter new_writer = new ElementWriter();
							new_writer.Begin(element.GetXObject(), true);
							ProcessElements(reader, new_writer);
							new_writer.End();
							reader.End();

							break;
						}
					default:
						{
							writer.WriteElement(element);
							break;
						}		
				}
			}
		}
	}
}
```

{% 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/elementedittest.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.
