Search code examples
xamarin.iosiphone-4airprint

iPhone 4.2 airprint Print job fails


No matter which printer I select, I get "Print-job failed: Unsupported document format "application/pdf".

I am trying to print on HP printers only.

I see no place in code to change the output type.

I am using UISimpleTextFormatter to format the string.

Not sure how to get around this one.

Edit : Code below is straight up from Miguel's example. with the only difference being, I tried out the markupformatter to see whether it gets output in a different format than application/pdf.

The print dialog comes up with the list of HP printers, I select a printer but nothing gets printed and in debug mode, the error specified at the top gets logged.

Other than UIPrintInfoOutputType.General, I have also tried UIPrintInfoOutputType.GrayScale but with the same effect.

public partial class AppDelegate : UIApplicationDelegate
    {
        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            window.MakeKeyAndVisible ();
            var button = UIButton.FromType (UIButtonType.RoundedRect);
            button.Frame = new RectangleF (100, 100, 120, 60);
            button.SetTitle ("Print", UIControlState.Normal);
            button.TouchDown += delegate {
                Print ();
            };
            window.AddSubview (button);
            return true;
        }

        void Print ()
        {
            var printInfo = UIPrintInfo.PrintInfo;
            printInfo.JobName = "Test :";
            printInfo.OutputType = UIPrintInfoOutputType.General;
            printInfo.JobName = "Test: 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 htmlFormatter = new UIMarkupTextPrintFormatter("<html><body>Test : Hi There!!</body></html>");
            htmlFormatter.StartPage = 0;
            htmlFormatter.ContentInsets = new UIEdgeInsets (72, 72, 72, 72); // 1 inch margins
            htmlFormatter.MaximumContentWidth = 6 * 72;                 

            var printer = UIPrintInteractionController.SharedPrintController;
            printer.PrintInfo = printInfo;
            printer.PrintFormatter = htmlFormatter;
            printer.ShowsPageRange = true;
            printer.Present (true, (handler, completed, err) => {
                if (!completed && err != null){
                    Console.WriteLine ("error");
                }
            });
        }

        public override void OnActivated (UIApplication application)
        {
        }
    }

Solution

  • I was expecting the print dialog to come up with only the air print enabled printers. But it comes up with non airprint enabled HP printers as well. That amde me think, it could print to those printers and that they are air print enabled.

    But that was not the case.