Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

Xamarin / Guides / Code sharing



PDFTron is now Apryse, learn more here.

Code sharing between Xamarin.Android app and Xamarin.iOS app

Shared classes

Apryse for Xamarin SDK takes advantage of PInvoke which allows calling C functions from C# directly. As a result, majority of Apryse classes share the same API between Xamarin.Android and Xamarin.iOS. For example, you can find AndroidMiscellaneousSamples and iOSMiscellaneousSamples in the download packages which share all of their source code.

This guide demonstrates how to structure your project to allow code sharing. Platform specific classes will be listed at the end of this guide.

First, create a Common folder outside of both apps, for example:


Common folder will be where all the shared source files live. For example, let's say we have a Common/CreateSticky.cs file for creating sticky note annotations.

Now, when open each of the Xamarin.iOS or Xamarin.Android project in Visual Studio, add CreateSticky.cs as a linked item:

In Visual Studio for Mac:

  • Right click on the project
  • Click Add > Add Files...
  • Select Common/CreateSticky.cs
  • Choose Add a link in the Add File To Folder dialog

In Visual Studio 2017:

  • Right click on the project
  • Click Add > Existing item...
  • Select Common/CreateSticky.cs, in the same dialog, instead of Add button, click the down arrow and select Add As Link

native folder

And that is it! You can use Apryse pdftron.PDF.Annot class to create the sticky note in a file that is now shared between Xamarin.Android and Xamarin.iOS apps.

Platform specific classes

List of platform specific classes:

  • pdftron.PDF.PDFViewCtrl
  • All classes under pdftron.PDF.Tools namespace
  • All classes under pdftron.PDF.Controls namespace

Get the answers you need: Support