We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create a PDF file in Xamarin?

Platform: Xamarin.Forms |
Control: PDF

Syncfusion Essential PDF is a Xamarin PDF library used to create, read, and edit PDF documents. Using this library, you can create a PDF document in Xamarin.

Steps to create PDF programmatically:

  1. Create a new C# Xamarin.Forms application project. Create Xamarin.Forms application
  2. Select a project template and required platforms to deploy the application. In this application, the portable assemblies to be shared across multiple platforms, the .NET Standard code sharing strategy has been selected. For more details about code sharing, refer here.

    If .NET Standard is not available in the code sharing strategy, the Portable Class Library (PCL) can be selected.

Select Blank App template in Xamarin

  1. Install the Syncfusion.Xamarin.PDF NuGet package as a reference to your  .NET Framework applications from NuGet.org. Install required Nuget packages in Xamarin
  2. Add new Forms XAML page in portable project if there is no XAML page is defined in the App class. Otherwise, proceed to the next step.
  1. To add the new XAML page, right-click the project and select Add > New Item and add a Forms XAML Page from the list. Name it as MainXamlPage.
  2. In App class of portable project (App.cs), replace the existing constructor of App class with the following code snippet, which invokes the MainXamlPage.
    public App()
        // The root page of your application
        MainPage = new MainXamlPage();


  1. In the MainXamlPage.xaml, add new button as follows.
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 x:Class="GettingStarted. MainXamlPage">
    <StackLayout VerticalOptions="Center">
    <Button Text="Generate Document" Clicked="OnButtonClicked" HorizontalOptions="Center"/>


  1. Include the following namespace in the MainXamlPage.xaml.cs file.
    using Syncfusion.Pdf;
    using Syncfusion.Pdf.Graphics;
    using Syncfusion.Drawing;


  1. Include the following code snippet in the click event of the button in MainXamlPage.xaml.cs, to create a PDF file and save it in a stream.
    // Create a new PDF document
    PdfDocument document = new PdfDocument();
    //Add a page to the document
    PdfPage page = document.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Set the standard font
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
    //Draw the text
    graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
    //Save the document to the stream
    MemoryStream stream = new MemoryStream();
    //Close the document
    //Save the stream as a file in the device and invoke it for viewing
    Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView("Output.pdf", "application / pdf", stream);


  1. Download the helper files from this link and add them into the mentioned project. These helper files allow you to save the stream as a physical file and open the file for viewing.


File Name


Portable project


Represent the base interface for save operation

iOS Project


Save implementation for iOS device


Helper class for viewing the PDF file in iOS device

Android project


Save implementation for Android device

WinPhone project


Save implementation for Windows phone device

UWP project


Save implementation for UWP device.

Windows(8.1) project


Save implementation for WinRT device.



Introduced a new runtime permission model for the Android SDK version 23 and above. So, include the following code for enabling the Android file provider to save and view the generated PDF document.

  • Create a new XML file with the name of provider_paths.xml under the Android project Resources folder and add the following code in it.

          Eg: Resources/xml/provider_paths.xml

<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <external-path name="external_files" path="."/>
  • Add the following code to the AndroidManifest.xml file located under Properties/AndroidManifest.xml.
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname. GettingStarted ">
     <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
     <application android:label=" GettingStarted.Android">
        <provider android:name="android.support.v4.content.FileProvider"
          <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
                     android:resource="@xml/provider_paths" />


  1. Compile and execute the application. This creates a simple PDF document.

By executing the program, you will get the PDF document as follows. Screenshot of output PDF file in Xamarin

Download the complete work sample from Create_PDF_file.zip.

Take a moment to peruse the documentation, where you can find other options like drawing right-to-left text and multi-column text,  consuming TrueType fonts, Standards fonts, and CJK fonts. Also, the features like PDF form filling, extract text or images from PDF, and protect PDF documents with code examples.

Refer here to explore the rich set of Syncfusion Essential PDF features.

See Also:

Create a PDF file in ASP.NET Core

Create a PDF file in ASP.NET MVC

Create a PDF file in Windows Forms

Create a PDF file in WPF


Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.


2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment
Feb 27, 2019

this is not work.please help!

Prakash Viswanathan [Syncfusion]
Mar 01, 2019

Hi Ibrahim 


We suspect that you are facing the runtime permission issue in Android.


From Android version 6.0(Marshmallow) and above, we need to grant runtime permission to save the PDF in the device. More details about this can be found in this link.

We have modified this KB with the workable sample, could you please try the same and let us know if it works.


Link : http://www.syncfusion.com/downloads/support/directtrac/general/ze/GettingStarted-822055283 



Prakash V

Francisco Jimenez
Apr 16, 2019

the example does not work

Surya Kumar [Syncfusion]
Apr 17, 2019

Hi Francisco,

Please try using the sample from the main KB link. Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/GettingStarted-764544620

Regards, Surya Kumar

Francisco Jimenez
Apr 19, 2019

to upload an image to the pdf in xamarin ios, how is it done?

Sowmiya Loganathan [Syncfusion]
Apr 22, 2019

Hi Francisco,

Please try the below code snippet to add image in PDF document from UG documentation link, https://help.syncfusion.com/file-formats/pdf/working-with-images?cs-save-lang=1&cs-lang=xamarin

Regards, Sowmiya L

Jordan Capa
Apr 23, 2019

thanks for the helpful information! for the beginners and want to save time, I found zetpdf.com i heard a lot of this. I suggest it because it's the fastest pdf SKD for .NET applications.

Francisco Jimenez
Apr 26, 2019

but the image in the folder must be in the portable project or android project or ios project

Stream imageStream = typeof (App) .GetTypeInfo (). Assembly.GetManifestResourceStream ("Sample.Assets.Autumn Leaves.jpg");

Luis David
May 29, 2019

Hi I'm using the example code but got a proble with this line: Xamarin.Forms.DependencyService.Get().SaveAndView("Output.pdf", "application / pdf", stream);I'm getting System.NullReferenceException Any idea why?

Surya Kumar [Syncfusion]
May 30, 2019

Hi Luis,

Could you please try using the sample which is provided in this KB it can be downloaded from below link:


This sample works fine without any issues. Kindly try the same and let us know if the issue still occurs.

Regards, Surya Kumar

Luis David
May 30, 2019

Thanks Surya Kumar [Syncfusion]

The sample you give works fine but, when I try to replicate it in my app I'm still getting the same problem the exception says: System.NullReference Exception : Object reference not set to an instance of an object.(System.Object sender, System.EventArgs args) [0x00060] then it gives me the path of the app, but the path where i am working the app(i mean the desktop path, not the path of the phone app )

Luis David
May 30, 2019

Already found the problem, cause is a helper file i guess it was just for help not obligatory, but it was i was missing de SaveAndroid.cs, by the way, thanks.

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile