Aspose.Slides for Xamarin

Overview

Xamarin is a framework for cross-platform mobile development using .NET C#. Xamarin is having tools and libraries that extend the possibilities of the .NET platform and allow building applications for any mobile OS: Android, iOS and Windows. For development in Xamarin, programmers can use their usual environment including C#, Visual Studio, 3-rd party libraries.

Aspose.Slides API can work in Xamarin platform. For that, the Aspose.Slides .NET package includes a separate dll for Xamarin. Aspose.Slides for Xamarin supports most features available in .NET version:

  • presentation conversion and viewing.
  • presentation content editing: text, shapes, charts, SmartArt, audio/video, fonts, etc.
  • animation, 2D effects, WordArt, etc.
  • metadata and document properties.
  • printing, cloning, merging, comparing, splitting, etc.

The full features comparison is available in this topic below.

In Aspose.Slides for Xamarin API the classes, namespaces, logic and behaviour are as close as possible to the .NET version. You may migrate your Aspose.Slides .NET applications to Xamarin with the minimal costs.

Quick Example

Aspose.Slides for Xamarin can be used to build and use your C# application using Slides for Android. Below is a simple example of Android via Xamarin application that uses Aspose.Slides to display presentation slides and adding a new shape on the slide by touch. Full sources of the example are available on GitHub.

Let’s start from creating a Xamarin Android App:

todo:image_alt_text

First, we create a content layout that will contain an image view and Prev, Next buttons:

todo:image_alt_text

XML - content_main.xml - Create content layout


 <LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:orientation=    "vertical"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:showIn="@layout/activity_main">

    <LinearLayout

        android:orientation="horizontal"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_weight="1"

        android:id="@+id/linearLayout1">

        <ImageView

            android:src="@android:drawable/ic_menu_gallery"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:id="@+id/imageView"

            android:scaleType="fitCenter" />

    </LinearLayout>

    <LinearLayout

        android:orientation="horizontal"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_weight="10"

        android:id="@+id/linearLayout2">

        <Button

            android:text="Prev"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:id="@+id/buttonPrev" />

        <Button

            android:text="Next"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:id="@+id/buttonNext"/>

    </LinearLayout>

</LinearLayout>

Then we will reference the “Aspose.Slides.Droid.dll” library, include sample presentation (“HelloWorld.pptx”) into Xamarin application Assets and add it’s initialization into MainActivity:

C# - MainActivity.cs - Initialization


 [Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]

public class MainActivity : AppCompatActivity

{

    private Aspose.Slides.Presentation presentation;



    protected override void OnCreate(Bundle savedInstanceState)

    {

        base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.activity_main);

    }



    protected override void OnResume()

    {

        if (presentation == null)

        {

            using (Stream input = Assets.Open("HelloWorld.pptx"))

            {

                presentation = new Aspose.Slides.Presentation(input);

            }

        }

    }

    protected override void OnPause()

    {

        if (presentation != null)

        {

            presentation.Dispose();

            presentation = null;

        }

    }

}

Let’s add displaying Prev and Next slide on buttons click:

C# - MainActivity.cs - Display slides on Prev and Next button click


 [Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]

public class MainActivity : AppCompatActivity

{

    private Button buttonNext;

    private Button buttonPrev;

    ImageView imageView;

    private Aspose.Slides.Presentation presentation;

    private int currentSlideNumber;

    protected override void OnCreate(Bundle savedInstanceState)

    {

        base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.activity_main);

    }



    protected override void OnResume()

    {

        base.OnResume();

        LoadPresentation();

        currentSlideNumber = 0;

        if (buttonNext == null)

        {

            buttonNext = FindViewById<Button>(Resource.Id.buttonNext);

        }

        if (buttonPrev == null)

        {

            buttonPrev = FindViewById<Button>(Resource.Id.buttonPrev);

        }

        if(imageView == null)

        {

            imageView= FindViewById<ImageView>(Resource.Id.imageView);

        }

        buttonNext.Click += ButtonNext_Click;

        buttonPrev.Click += ButtonPrev_Click;

        RefreshButtonsStatus();

        ShowSlide(currentSlideNumber);

    }

    private void ButtonNext_Click(object sender, System.EventArgs e)

    {

        if (currentSlideNumber > (presentation.Slides.Count - 1))

        {

            return;

        }

        ShowSlide(++currentSlideNumber);

        RefreshButtonsStatus();

    }

    private void ButtonPrev_Click(object sender, System.EventArgs e)

    {

        if (currentSlideNumber == 0)

        {

            return;

        }

        ShowSlide(--currentSlideNumber);

        RefreshButtonsStatus();

    }

    protected override void OnPause()

    {

        base.OnPause();

        if (buttonNext != null)

        {

            buttonNext.Dispose();

            buttonNext = null;

        }

        if (buttonPrev != null)

        {

            buttonPrev.Dispose();

            buttonPrev = null;

        }

        if(imageView != null)

        {

            imageView.Dispose();

            imageView = null;

        }

        DisposePresentation();

    }

    private void RefreshButtonsStatus()

    {

        buttonNext.Enabled = currentSlideNumber < (presentation.Slides.Count - 1);

        buttonPrev.Enabled = currentSlideNumber > 0;

    }

    private void ShowSlide(int slideNumber)

    {

        Aspose.Slides.Drawing.Xamarin.Size size = presentation.SlideSize.Size.ToSize();

        Aspose.Slides.Drawing.Xamarin.Bitmap bitmap = presentation.Slides[slideNumber].GetThumbnail(size);

        imageView.SetImageBitmap(bitmap.ToNativeBitmap());

    }

    private void LoadPresentation()

    {

        if(presentation != null)

        {

            return;

        }

        using (Stream input = Assets.Open("HelloWorld.pptx"))

        {

            presentation = new Aspose.Slides.Presentation(input);

        }

    }

    private void DisposePresentation()

    {

        if(presentation == null)

        {

            return;

        }

        presentation.Dispose();

        presentation = null;

    }

}

Finally, let’s implement adding an ellipse shape by touch on the slide:

C# - MainActivity.cs - Add ellipse by slide click


 private void ImageView_Touch(object sender, Android.Views.View.TouchEventArgs e)

{

    int[] location = new int[2];

    imageView.GetLocationOnScreen(location);

    int x = (int)e.Event.GetX();

    int y = (int)e.Event.GetY();

    int posX = x - location[0];

    int posY = y - location[0];

    Aspose.Slides.Drawing.Xamarin.Size presSize = presentation.SlideSize.Size.ToSize();

    float coeffX = (float)presSize.Width / imageView.Width;

    float coeffY = (float)presSize.Height / imageView.Height;

    int presPosX = (int)(posX * coeffX);

    int presPosY = (int)(posY * coeffY);

    int width = presSize.Width / 50;

    int height = width;

    Aspose.Slides.IAutoShape ellipse = presentation.Slides[currentSlideNumber].Shapes.AddAutoShape(Aspose.Slides.ShapeType.Ellipse, presPosX, presPosY, width, height);

    ellipse.FillFormat.FillType = Aspose.Slides.FillType.Solid;



    Random random = new Random();

    Aspose.Slides.Drawing.Xamarin.Color slidesColor = Aspose.Slides.Drawing.Xamarin.Color.FromArgb(random.Next(256), random.Next(256), random.Next(256));

    ellipse.FillFormat.SolidFillColor.Color = slidesColor;

    ShowSlide(currentSlideNumber);

}

By each click on the presentation slide, an ellipse of a random color is added:

todo:image_alt_text

Supported Features

FEATURES Aspose.Slides for .NET  Aspose.Slides for Xamarin
Presentation features  
Create new presentations ticktick
PowerPoint 97 - 2003 formats open/save ticktick
PowerPoint 2007 formats open/save ticktick
PowerPoint 2010 extensions support ticktick
PowerPoint 2013 extensions support ticktick
PowerPoint 2016 features support restrictedrestricted
PowerPoint 2019 features support restricted restricted
PPT 2 PPTX conversion ticktick
PPTX 2 PPT conversion ticktick
PPTX in PPT restrictedrestricted
Themes processing ticktick
Macros processing ticktick
Document properties processing ticktick
Password protection ticktick
Fast text extraction ticktick
Embedding fonts ticktick
Comments rendering tick  tick
Interrupting of long-running tasks ticktick  
Export formats:   
PDF ticktick
XPS ticktick
HTML ticktick
TIFF tickcircle
ODP restricted restricted
SWF restricted restricted
SVG ticktick
Import formats:   
HTML restrictedrestricted
ODP ticktick
THMX ticktick
Master slides features:   
Access all existing master slide ticktick
Create/remove master slides ticktick
Clone master slides ticktick
Layout slides features:   
Access all existing layout slides ticktick
Create/remove layout slides ticktick
Clone layout slides ticktick
Slide features:   
Access all existing slides ticktick
Create/remove slides ticktick
Clone slides ticktick
Export slides to images ticktick
Create/edit/remove slide sections ticktick
Notes slides features  
Access all existing notes slides ticktick
Shape features:   
Access all slide shapes ticktick
Add new shapes ticktick
Clone shapes ticktick
Export separate shapes to images ticktick
Supported shape types:   
All predefined shape types ticktick
Picture frames ticktick
Tables ticktick
Charts ticktick
SmartArt ticktick
Legacy diagram ticktick
WordArt ticktick
OLE, ActiveX objects restrictedrestricted
Video frames ticktick
Audio frames ticktick
Connectors ticktick
Group shape features:   
Access group shapes ticktick
Create group shapes ticktick
Ungroup existing group shapes ticktick
Shape effects features:   
2D effects restricted restricted
3D effects circlecircle
Text features:   
Paragraphs formatting ticktick
Portions formatting ticktick
Animation Features:   
Export animation to SWF circlecircle
Export animation to HTML circlecircle