> 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/xamarin/forms/fill-fields.md).

# Fill Forms

Learn how to create, edit, and fill PDF forms in Xamarin.Android and Xamarin.iOS using Apryse SDK. Fill form fields programmatically or with the UI component for seamless interaction. Access interacti

Apryse SDK allows you to crop pages to your required size parameters.

{% tabs %}
{% tab title="Android" %}

## Create, edit & fill PDF forms in Xamarin.Android

You can fill form fields in a document using the UI component or programmatically with the Xamarin.Android API.

[UI Component](/xamarin/guides/android/form-fields/fill-fields.md#ui-component) The document viewer allows you to directly interact with and change values in form fields

[API guide](/xamarin/guides/android/form-fields/fill-fields.md#api-guide) You can programmatically fill and modify form fields in documents
{% endtab %}

{% tab title="iOS" %}

## Create, edit & fill PDF forms in Xamarin.iOS

To fill and set values for existing form fields.

{% code lineNumbers="true" %}

```csharp
PDFDoc doc = new PDFDoc(filename);

// Search for a specific field
Field fld = doc.GetField("employee.name.first");
fld.SetValue("John");
```

{% endcode %}

[PDF Interactive Forms (AcroForms)](/xamarin/get-started/samples.md#interactiveforms) Full code sample which illustrates some basic PDFNet capabilities related to interactive forms (also known as AcroForms).

## About filling form fields

Form Fields can be populated using the `Field.SetValue()` method:

{% code lineNumbers="true" %}

```csharp
field.SetValue("New Value");

// Regenerate appearance stream.
field.RefreshAppearance();
```

{% endcode %}

Note that, after modifying the Field's value, we refreshed its appearance stream. In the PDF format, Field's value and appearance are two different entities. Therefore, if you don't call `RefreshAppearance()`, the initial value on a PDF page will remain unchanged — it may have retain the old value or it may be blank.

One approach used by other PDF libraries is to let the PDF viewer automatically pre-generate appearance streams by setting the 'NeedAppearances' flag in AcroForm dictionary:

{% code lineNumbers="true" %}

```csharp
doc.GetAcroForm().PutBool("NeedAppearances", true);
```

{% endcode %}

This will force viewer applications to auto-generate appearance streams every time the document is opened. This method is unreliable — Acrobat does not always generate appearance streams correctly. Another disadvantage of this approach is that the user will always be prompted to save the document even if the document was never modified.

`Field.GetValueAsString()` returns the field's value as a string. The value returned varies based on the field type. A text field type varies depending on the field type. A text field will return a string:

{% code lineNumbers="true" %}

```csharp
if (type == Field.FieldType.e_text && field.GetValue())
{
  Console.WriteLine("Field value: {0}", field.GetValueAsString());
}
else
{
  Console.WriteLine("Field is blank");
}
```

{% endcode %}

Other field types, such as check boxes and radio buttons, can also return text from `GetValueAsString()`. Similarly, the `Field.GetValueAsString()` method is available.

## Access interactive fields

The form shown in the following figure consists of a number of Fields:

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-d05d655d676590f4499e02d95420b4bfe8c76f2b%2Fd34fbd5ce2b4792f76058f58f4e5d391153db51e-450x434.gif?alt=media)

Every field has its name and value, as well as its annotation appearance.

In the Apryse SDK, Fields are accessed through `FieldIterators`.

For example, the list of all Fields present in the document can be traversed using the following code snippet:

{% code lineNumbers="true" %}

```csharp
FieldIterator itr;
for(itr=doc.GetFieldIterator(); itr.HasNext(); itr.Next())
{
  Field field = itr.Current();
  Console.WriteLine("Field name: {0}",field.GetName());
}
```

{% 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/xamarin/forms/fill-fields.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.
