Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
Created November 22, 2016 21:00
Show Gist options
  • Save dannycabrera/b7cb3ac32d27d2c4cacd6028b1978df5 to your computer and use it in GitHub Desktop.
Save dannycabrera/b7cb3ac32d27d2c4cacd6028b1978df5 to your computer and use it in GitHub Desktop.
Printing PDF with UIKit.UIPrint on Xamarin.iOS
using UIKit;
void AirPrint (CGRect frame, string pdfOrImageToPrint)
{
var printer = UIPrintInteractionController.SharedPrintController;
if (printer == null) {
Console.WriteLine("Unable to print at this time.");
} else {
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Print Job Name";
printer.PrintInfo = printInfo;
printer.PrintingItem = NSUrl.FromFilename (pdfOrImageToPrint);
printer.ShowsPageRange = true;
var handler = new UIPrintInteractionCompletionHandler ((printInteractionController, completed, error) => {
if (completed) {
Console.WriteLine("Print Completed.");
} else if (!completed && error != null) {
Console.WriteLine("Error Printing.");
}
});
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
printer.PresentFromRectInView (frame, View, true, handler);
else
printer.Present (true, handler);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment