1

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

CF_Maintainer
  • 973
  • 2
  • 12
  • 30
  • Can you post some code on how to do this in Objective-C, if it's not too long? As far as I know, the whole Cocoa Touch framework is exposed to .NET apps in MonoTouch, so it should be easily portable. – onitake Apr 25 '11 at 14:48
  • I stubled upon these examples, both in objC http://www.iphonedevsdk.com/forum/iphone-sdk-development/67176-airprint-tutorial-simple-print-file-30-lines-code.html and this http://stackoverflow.com/questions/5690931/objective-c-code-for-airprint – CF_Maintainer Apr 25 '11 at 14:56
  • 1
    it looks like all of the UIPrint* classes are exposed in MT, so you should be able to do it. – Jason Apr 25 '11 at 15:14
  • Jason, Thanks for pointing that out. Do you have an example of doing it in MT. If yes if you could post that so that I can mark it as an answer. – CF_Maintainer Apr 25 '11 at 15:24
  • 1
    Translating Obj-C code to C# is a skill you're going to need to have if you are going to be using MonoTouch as Novell has kept the names of things exactly the same. For the most part it is as simple as translating the syntax. If you have already looked for such examples of printing in MonoTouch on Google, then I would suspect an example doesn't exist. – jonathanpeppers Apr 25 '11 at 17:40
  • Thanks for the comment Jonathon. That effectively means learning Objective-C quote a bit. Now, I am not sure what the value proposition of monotouch is? – CF_Maintainer Apr 27 '11 at 20:10
  • It's not that hard to look at and figure out what it's doing. I learned the basic syntax and can figure out what ObjC code is doing, and then do a little mental gymnastics to convert to C#. – Derreck Dean Oct 25 '12 at 16:08

1 Answers1

1

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");
        }
    });
}
miguel.de.icaza
  • 32,654
  • 6
  • 58
  • 76
  • Miguel, I ran the sample (in the emulator) and it did not find any printers. How do I find the list of network printers it is considering to use? – CF_Maintainer Apr 27 '11 at 17:20
  • Miguel, I got the printers to show up. Another problem. I get this everytime for every printer "Print -job" failed: unsupported document-format 'application/pdf'. Not sure where to change the output format. – CF_Maintainer Apr 27 '11 at 19:09