iPhone 4.2 airprint 打印作业失败

发布于 2024-11-03 20:42:03 字数 2463 浏览 1 评论 0原文

无论我选择哪台打印机,我都会收到“打印作业失败:不支持的文档格式“application/pdf”。

我尝试仅在 HP 打印机上进行打印。

我在代码中没有看到可以更改 我正在使用UISimpleTextFormatter

来格式化字符串。

编辑:下面的代码直接来自 Miguel 的示例,唯一的区别是 我尝试了标记格式化程序,看看它是否以与 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)
        {
        }
    }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆蝶 2024-11-10 20:42:03

我期望打印对话框仅显示支持空中打印的打印机。但它也配备了不支持 AirPrint 的 HP 打印机。我认为,它可以打印到这些打印机,并且它们支持空中打印。

但事实并非如此。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文