Create Word file in Xamarin

GemBox.Document is a standalone .NET component with cross-platform support. You can use it on non-Windows platforms like Xamarin and Mono, enabling you to run it on Android and iOS mobile devices.

With GemBox.Document you can process your documents (read, write, convert, and edit Word files) from the native mobile apps.

The following example shows how you can create a Word file in Xamarin.Forms mobile application.

Word file generator on a native Android mobile app with Xamarin.Forms
Screenshot of Xamarin Android app that creates a Word file
<ContentPage xmlns=""

    <StackLayout Padding="50" 

        <Label Text="GemBox.Document Example"
               Margin="0,0,0,30" />

        <Editor x:Name="text"
                Text="Hi! This document was generated with GemBox.Document library." />

        <ActivityIndicator x:Name="activity" />

        <Button x:Name="button"
                Text="Create document"

using System;
using System.ComponentModel;
using System.IO;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
using GemBox.Document;

public partial class MainPage : ContentPage
    public MainPage()

    private string CreateDocument()
        var document = new DocumentModel();

        document.Sections.Add(new Section(document,
            new Paragraph(document, text.Text)));

        var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Example.docx");


        return filePath;

    private async void Button_Clicked(object sender, EventArgs e)
        button.IsEnabled = false;
        activity.IsRunning = true;

            var filePath = await Task.Run(() => CreateDocument());
            await Launcher.OpenAsync(new OpenFileRequest(Path.GetFileName(filePath), new ReadOnlyFile(filePath)));
        catch (Exception ex)
            await DisplayAlert("Error", ex.Message, "Close");

        activity.IsRunning = false;
        button.IsEnabled = true;
Imports System
Imports System.ComponentModel
Imports System.IO
Imports System.Threading.Tasks
Imports Xamarin.Essentials
Imports Xamarin.Forms
Imports GemBox.Document

Partial Public Class MainPage
    Inherits ContentPage

    Public Sub New()
    End Sub

    Private Function CreateDocument() As String
        Dim document As New DocumentModel()

        document.Sections.Add(New Section(document,
            New Paragraph(document, Text.Text)))

        Dim filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Example.docx")


        Return filePath
    End Function

    Private Async Sub Button_Clicked(sender As Object, e As EventArgs)
        button.IsEnabled = False
        activity.IsRunning = True

            Dim filePath = Await Task.Run(Function() CreateDocument())
            Await Launcher.OpenAsync(New OpenFileRequest(Path.GetFileName(filePath), New ReadOnlyFile(filePath)))
        Catch ex As Exception
            Await DisplayAlert("Error", ex.Message, "Close")
        End Try

        activity.IsRunning = False
        button.IsEnabled = True
    End Sub
End Class

Limitations on Android or iOS

You can use the full functionality of GemBox.Document on the Xamarin applications, but with the following exceptions:

These features currently have WPF dependencies which means they require a .NET Windows Desktop Runtime. However, we do have plans for providing cross-platform support for them in future releases.

See also

Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy