Search code examples
iphoneprintingxamarin.iosairprint

MonoTouch : Print to Network printer


I am really new to iPhone dev.

I am evaluating whether to use Monotouch or objC for a potential app.

The app needs to be able to print pictures to a network printer.

I have seen couple of posts about how to do it using cocoa touch/objc.

Could not find any examples of doing this using monotouch.

Is this doable/supported using MonoTouch?

This is a must have feature.

Thanks


Solution

  • This should do it, I have checked this into:

    http://github.com/migueldeicaza/monotouch-samples in the "print" directory:

    void Print ()
    {
        var printInfo = UIPrintInfo.PrintInfo;
        printInfo.OutputType = UIPrintInfoOutputType.General;
        printInfo.JobName = "My first Print Job";
    
        var textFormatter = new UISimpleTextPrintFormatter ("Once upon a time...") {
            StartPage = 0,
            ContentInsets = new UIEdgeInsets (72, 72, 72, 72),
            MaximumContentWidth = 6 * 72,
        };
    
        var printer = UIPrintInteractionController.SharedPrintController;
        printer.PrintInfo = printInfo;
        printer.PrintFormatter = textFormatter;
        printer.ShowsPageRange = true;
        printer.Present (true, (handler, completed, err) => {
            if (!completed && err != null){
                Console.WriteLine ("error");
            }
        });
    }