2011-04-27 99 views
1

无论我选择哪台打印机,我得到“打印作业失败:不支持的文件格式‘应用程序/ PDFiPhone 4.2的AirPrint打印作业失败

我试图打印仅适用于HP打印机

我看到的代码没有地方改变输出类型。

我使用UISimpleTextFormatter格式化字符串。

不知道如何获得ARO这一个。

编辑:下面的代码是从米格尔的例子中直接找到的。唯一的区别是,我尝试使用markupformatter来查看它是否以不同于application/pdf的格式输出。

打印对话框出现在HP打印机列表中,我选择了打印机,但没有打印出来,并且在调试模式下,记录了顶部指定的错误。

除了UIPrintInfoOutputType.General,我也曾尝试UIPrintInfoOutputType.GrayScale但具有相同的效果。

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) 
     { 
     } 
    } 
+0

你可以发布一些示例代码吗? – iamandrus 2011-04-27 20:19:27

回答

1

我期待打印对话框只能打印出启用了打印功能的打印机。但它也提供了不支持Airprint的惠普打印机。这是我想的,它可以打印给那些打印机,并且它们是启用了打印功能的。

但事实并非如此。