Displaying a PDF Word Excel RTF Images in Xamarin iOS

Displaying a common document in iOS is very simple and works very well… but only once you know how…

Being that Xamarin.iOS is just a wrap around the Native iOS API means that you must do it the Apple way.

In iOS there’s a controller named QLPreviewController and this is what you need to display documents. The quicklook supports a bunch of different formats and does it really well, these include iWork documents, Microsoft Office documents (Word, Excel, etc), Rich Text Format (RTF) documents, PDF file, Images, Text Files, CSV files.

The trick is that the QLPreviewController requires a preview item and a datasource. To setup your datasource you need to inherit from QLPreviewControllerDataSource as per the example below.

The datasource requires a QLPreviewItem. Since you can access both Bundled File and Files Directly from the file-system I’ve created two different QLPreviewItems as per the example below.

Once you have that then putting it all together is simple.






2 Responses

  1. Hi Michael.
    I would like to use your code in a “DependencyService”, but I’m not able to compile it.

    I would like to have something like

    public class MyOpenFile : IOpenFile
    public MyOpenFile ()

    public void OpenFile(string filePath)
    string filename = System.IO.Path.GetFileName (filePath);
    string currentFilePath = System.IO.Path.GetDirectoryName (filePath);

    QLPreviewItemBundle prevItem = new QLPreviewItemBundle (filename, currentFilePath);
    QLPreviewController previewController = new QLPreviewController ();
    previewController.DataSource = new PreviewControllerDS (prevItem);
    NavigationController.PushViewController (previewController, true);

    But I’ve an error in NavigationController.PushView…. row

    How can I open documents in iOS using DependencyService and Xamarin Forms?

Leave a Reply