どのプリンターを選択しても、「Print-job failed: Unsupported document format "application/pdf " というメッセージが表示されます。
HP プリンターでのみ印刷しようとしています。
コードに出力タイプを変更する場所がありません。
UISimpleTextFormatterを使用して文字列をフォーマットしています。
これを回避する方法がわかりません。
編集:以下のコードは、ミゲルの例からまっすぐです。唯一の違いは、マークアップフォーマッターを試して、 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)
{
}
}