> 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/basic-operations/basics/add-page.md).

# Add new pages to existing PDF document in Xamarin

Learn how to use the AddPageDialogFragment in Xamarin.Android to create new pages with different types, sizes, and colors for your PDF documents. Customize your pages with various properties like Page

{% hint style="info" %}
**This tutorial only applies to Xamarin.Android.**
{% endhint %}

The [`AddPageDialogFragment`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Controls.AddPageDialogFragment.html) allows users are able to add new pages to an existing document or create a completely new document. The new pages created can have various types, sizes, and colors.

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-de25653365e8f896fae4fd5a9d3d3a9465ad9f1a%2F8388d04f51e54f679e6e2075355c3bea138e8a1a-2300x2300.png?alt=media)

Add page dialog: dialog for creating new document (left), dialog for adding pages to an existing document (right).

## Page properties

The following properties are available for creating or adding pages:

* `PageType` The following types of page are supported in this dialog:
  * `Blank`: a page with nothing on it.
  * `Lined`: a page with horizontal lines on it.
  * `Grid`: a page with a superimposed grid on it.
  * `Graph`: a page with Cartesian axes on it.
  * `Music`: a page set up with modern staff notation for notating music.
* `PageSize` The following page sizes are supported in this dialog: `Custom`, `Letter`, `Legal`, `A4`, `A3`, `Ledger`.

{% hint style="info" %}
The `Custom` option is only available when adding new pages to an existing PDF document, not when a new document is being created. The page size of `Custom` option is specified as here: [add pages to an existing document](https://docs.apryse.com)
{% endhint %}

* `PageColor` The page background can be set to the following colors: `White`, `Yellow`, and `Blueprint`.

## Create a new PDF document

To create a new PDF document, call `newInstance()` and override the `OnCreateNewDocumentListener` interface. The implementation of `onCreateNewDocument(PDFDoc, String)` should create a new file with the given title normalized to a ".pdf" extension.

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

```csharp
var addPageDialogFragment = AddPageDialogFragment.NewInstance();
addPageDialogFragment.CreateNewDocument += (sender, e) =>
{
    if (e.PdfDoc == null || e.Title == null)
    {
        return;
    }
    var title = e.Title;
    if (!title.EndsWith(".pdf", true, null))
    {
        title = title + ".pdf";
    }
    Java.IO.File folder = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
    Java.IO.File documentFile = new Java.IO.File(folder, title);
    try
    {
        e.PdfDoc.Save(documentFile.AbsolutePath, (long)pdftron.SDF.SDFDoc.SaveOptions.e_remove_unused, null);
        Console.WriteLine("New file saved: " + documentFile.AbsolutePath);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    finally
    {
        e.PdfDoc.Close();
    }

};
addPageDialogFragment.Show(this.SupportFragmentManager, "add_page_dialog");
```

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

## Add pages to an existing document

To add pages to an existing PDF, create a new instance of the add page dialog fragment using `newInstance(double, double)` and provide the valid page width and page height arguments. These arguments will be used only if the user selects the `Custom` option in the Page Size dropdown. You also must implement the `OnAddNewPagesListener` interface and override `onAddNewPages(Page[])`, in which the implementation should add the provided pages to the document.

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

```csharp
var addPageDialogFragment = AddPageDialogFragment.NewInstance(myPageWidth, myPageHeight);
addPageDialogFragment.AddNewPages += (sender, e) =>
{
    if (mPdfDoc == null || mPdfViewCtrl == null)
    {
        return;
    }
    bool shouldUnlock = false;
    try
    {
        mPdfViewCtrl.DocLock(true);
        shouldUnlock = true;

        for (int i = 1, cnt = e.Pages.Length; i <= cnt; i++)
        {
            int newPageNum = mPdfViewCtrl.CurrentPage + i;
            var pageNative = e.Pages[i - 1];
            var page = TypeConvertHelper.ConvPageToManaged(pageNative);
            mPdfDoc.PageInsert(mPdfDoc.GetPageIterator(newPageNum), page);
        }
    }
    catch (PDFNetException ex)
    {
        Console.WriteLine(ex.GetMessage());
    }
    finally
    {
        if (shouldUnlock)
        {
            mPdfViewCtrl.DocUnlock();
        }
    }
    mPdfViewCtrl.UpdatePageLayout();
    mPdfViewCtrl.CurrentPage = mPdfViewCtrl.CurrentPage + 1;
    if (mSeekBar != null)
    {
        mSeekBar.SetProgress(mPdfViewCtrl.CurrentPage);
    }
};
addPageDialogFragment.Show(this.SupportFragmentManager, "add_page_dialog");
```

{% 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/basic-operations/basics/add-page.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.
