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

# SDF

Sample C# code to edit an existing PDF document at the object level by using the Apryse SDK Cos/SDF low-level API.

Sample C# code for editing an existing PDF document at the object level by using the Apryse SDK Cos/SDF low-level API. 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.Filters;
using pdftron.SDF;

using PDFNetUniversalSamples.ViewModels;

namespace PDFNetSamples
{
    public sealed class SDFTest : Sample
    {
        public SDFTest() :
            base("SDF", "The sample illustrates how to use basic Cos/SDF API to edit an existing document.")
        {
        }

        public override IAsyncAction RunAsync()
        {
            return Task.Run(new System.Action(async () => {
                WriteLine("--------------------------------");
                WriteLine("Starting SDF Test...");
                WriteLine("--------------------------------\n");
            
                string input_file_path = Path.Combine(InputPath, "fish.pdf");
                WriteLine("Opening input file " + input_file_path);

			    try
			    {
				    // Here we create a SDF/Cos document directly from PDF file. In case you have 
				    // PDFDoc you can always access SDF/Cos document using PDFDoc.GetSDFDoc() method.
				    SDFDoc doc = new SDFDoc(input_file_path);
				    doc.InitSecurityHandler();				

				    WriteLine("-------------------------------------------------");
                    WriteLine("Modifying info dictionary, adding custom properties, embedding a stream...");

				    Obj trailer = doc.GetTrailer();	// Get the trailer

				    // Now we will change PDF document information properties using SDF API

				    // Get the Info dictionary. 
				    DictIterator itr = trailer.Find("Info");	
				    Obj info;
				    if (itr.HasNext()) 
				    {
					    info = itr.Value();
					    // Modify 'Producer' entry.
					    info.PutString("Producer", "PDFTron PDFNet");

					    // Read title entry (if it is present)
					    itr = info.Find("Author"); 
					    if (itr.HasNext()) 
					    {
						    info.PutString("Author", itr.Value().GetAsPDFText() + "- Modified");
					    }
					    else 
					    {
						    info.PutString("Author", "Joe Doe");
					    }
				    }
				    else 
				    {
					    // Info dict is missing. 
					    info = trailer.PutDict("Info");
					    info.PutString("Producer", "PDFTron PDFNet");
					    info.PutString("Title", "My document");
				    }

				    // Create a custom inline dictionary within Info dictionary
				    Obj custom_dict = info.PutDict("My Direct Dict");

				    // Add some key/value pairs
				    custom_dict.PutNumber("My Number", 100);

				    Obj my_array = custom_dict.PutArray("My Array");

				    // Create a custom indirect array within Info dictionary
				    Obj custom_array = doc.CreateIndirectArray();	
				    info.Put("My Indirect Array", custom_array);
				
				    // Create indirect link to root
				    custom_array.PushBack(trailer.Get("Root").Value());

				    // Embed a custom stream (file my_stream.txt).
                    MappedFile embed_file = new MappedFile(Path.Combine(InputPath, "my_stream.txt"));
				    FilterReader mystm = new FilterReader(embed_file);
                    custom_array.PushBack(doc.CreateIndirectStream(mystm));

				    // Save the changes.
                    String output_file_path = Path.Combine(OutputPath, "sdftest_out.pdf");
                    await doc.SaveAsync(output_file_path, 0, "%PDF-1.4");
				    doc.Destroy();
				    WriteLine("Test completed.");
                    WriteLine("Done. Results saved in " + output_file_path);
                    await AddFileToOutputList(output_file_path).ConfigureAwait(false);
			    }
			    catch (Exception e) {
                    WriteLine(GetExceptionMessage(e));
                }

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

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/uwp/get-started/samples/sdftest.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
