无论我选择哪台打印机,我都会收到“ Print-job failed: Unsupported document format "application/pdf "。
我正在尝试仅在 HP 打印机上打印。
我在代码中看不到更改输出类型的地方。
我正在使用UISimpleTextFormatter来格式化字符串。
不知道如何解决这个问题。
编辑:下面的代码直接来自 Miguel 的示例。唯一的区别是,我尝试了 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)
{
}
}