2011-04-27 100 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的惠普打印機。這是我想的,它可以打印給那些打印機,並且它們是啓用了打印功能的。

但事實並非如此。