Printing PDF/Image with UIKit.UIPrint on Xamarin.iOS

Danny Cabrera
Nov 22, 2016 · 1 min read

Had a request to enable printing from an app and dug into UIKit.UIPrint. The two Xamarin examples I came across were printing to a roll-fed AirPrint printer and printing simple text but none printed documents, which is what I needed. Turns out that to print a PDF all I needed was to supply the file path in an NSUrl to PrintingItem and voila!

I created a simple method with two parameters, the frame so we can display a popover view when done on an iPad and the file path pdfOrImageToPrint. With this method I can pass a path to a PDF or Image and let UIPrintInteractionController do the rest.

If you need to print from a UIWebView, UITextView or MKMapView simply replace printer.PrintingItem with printer.PrintFormatter. These three system subclasses offer usable view print formatters so you can do the following:

printer.PrintFormatter = yourWebViewName.ViewPrintFormatter;

printer.PrintFormatter = yourTextViewNameViewPrintFormatter;

printer.PrintFormatter = yourMapViewName.ViewPrintFormatter

Hope this helps someone looking to print files from Xamarin.iOS. Happy Coding!

Danny Cabrera

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade