Created
November 22, 2016 21:00
-
-
Save dannycabrera/b7cb3ac32d27d2c4cacd6028b1978df5 to your computer and use it in GitHub Desktop.
Printing PDF with UIKit.UIPrint on Xamarin.iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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