Add page dialog

This tutorial only applies to Xamarin.Android.

Using the add page dialog in Xamarin.Android is identical to using AddPageDialogFragment in Android. See tutorial here.

For example, the equivalent of the example provided in the Android guide will be:

To add new pages to current PDF:

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");

To create a new PDF:

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");