【问题标题】:Issue while printing 2 pages from a WKWebView从 WKWebView 打印 2 页时出现问题
【发布时间】:2016-01-03 21:11:58
【问题描述】:

要求:我有一个名为wkWebViewWKWebview 对象。我想使用 Airprint 从我的打印机打印它的内容。我曾经使用 UIWebview 来执行此操作,但运行时 javascript 方法的要求让我切换到 WKWebview

@property (strong, nonatomic) WKWebView *wkWebView;

问题:我可以使用下面的代码打印内容。当我打印 1 页时,它打印得很完美。但是当我尝试打印 2 页时,首先打印第 2 页,然后打印第 1 页。我想按顺序打印页面。

代码:我目前在打印方法中使用此代码:

UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGrayscale;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexNone;


UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.showsNumberOfCopies = NO;
pic.printFormatter = _wkWebView.viewPrintFormatter;

UIButton *butn = (UIButton*)sender;

[pic presentFromRect:butn.frame
              inView:self.view
            animated:YES
   completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {

       //Do something
   }];

【问题讨论】:

  • 我已经用谷歌搜索页面尝试了你的代码,它可以工作。它以正确的顺序显示页面,所以我怀疑你在代码的另一个地方做了一些破坏它的事情。那么你能展示更多你拥有的代码吗?
  • @MahmoudAdam:我在这个 web 视图中加载了一个本地 html 文件(在 html 字符串中),而不是 google 搜索页面。不知道为什么会这样。
  • 您能否发布 html,因为我认为问题出在 html 本身而不是代码上

标签: ios objective-c printing wkwebview


【解决方案1】:

您是否尝试过单独打印页面?

我会将它们放入一个数组中,然后检查数组长度并运行代码以在 For 循环中打印页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 2019-12-09
    • 2021-01-22
    • 1970-01-01
    相关资源
    最近更新 更多