Load Non-Web Documents

PDF for offline use
Sample Code:
Related SDKs:

Let us know how you feel about this

Translation Quality


This recipe shows how to load a web page in a UIWebView control.


To show a document type other than HTML in a UIWebView:

  1. Add the document (for example, a PDF) to your Xamarin.iOS project. Set the Build Action to BundleResource. You can set the build action for a file by right-clicking on that file and and choosing Build Action in the menu that opens.
  1. Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
  1. Load the file using NSUrl and NSUrlRequest classes:
string fileName = "Loading a Web Page.pdf"; // remember case-sensitive
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;

Additional Information

iOS can display the following document types:

  • Excel (.xls & .xlsx)
  • Keynote (.key.zip)
  • Numbers (.numbers.zip)
  • Pages (.pages.zip)
  • PDF (.pdf)
  • PowerPoint (.ppt & .pptx)
  • Rich Text Format (.rtf)
  • Word (.doc & .docx)

See Technical Q&A 1630 for details on other supported file types.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.