【问题标题】:UIPrintInteractionController printingItems not showing up / workingUIPrintInteractionController printingItems 未显示/工作
【发布时间】:2019-02-01 23:59:19
【问题描述】:

很简单...

这些天,我认为自己是一名经验丰富的 iOS 开发人员,但这个似乎是 iOS 中的一个明显错误,除非我错过了什么。

请看下面的代码。

文件路径指向两个单页 PDF。

显示的是一个打印交互控制器,没有要打印的内容。

如果我一次只做 1 个文件:

pc.printingItem = [NSURL fileURLWithPath:filePath1];

它就像一个冠军。

我在这里错过了什么?!

UIPrintInteractionController *pc = [UIPrintInteractionController sharedPrintController];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
printInfo.orientation = UIPrintInfoOrientationLandscape;
pc.printInfo = printInfo;

pc.printingItems = @[[NSURL fileURLWithPath:filePath1], 
                     [NSURL fileURLWithPath:filePath2]];

[pc presentAnimated:YES completionHandler:completionHandler];

【问题讨论】:

  • 您找到解决问题的方法了吗?这里有完全相同的问题。可惜我们不得不处理这些愚蠢的事情。观察:PDF 实际上可以正确打印。用打印机模拟器检查。只是预览不显示!
  • 我在 swift、XCode 11 和 iOS 13 中也遇到了同样的问题 >
  • 能否提供filePath1和filePath2的绝对路径?

标签: ios objective-c swift items uiprintinteractioncntrler


【解决方案1】:

我遇到了同样的问题,并通过使用我的 PDF 文件的原始数据设置 printingItem 属性来解决它。

// Here is a class I created that works with `UIActivityViewController`,
// feel free to tweak to your needs.

final class CustomActivityViewController: UIActivityViewController {

    init(with filePath: URL, and fileData: Data?) {
        super.init(activityItems: [filePath], applicationActivities: [])
    
        completionWithItemsHandler = { activity, complete, items, error in
        
            if activity == .print {
            
                let printInfo = UIPrintInfo(dictionary: nil)
                printInfo.jobName = filePath.lastPathComponent
                printInfo.outputType = .general
            
                let printer = UIPrintInteractionController.shared
                printer.printingItem = fileData // <-- This is the cure.
                printer.printInfo = printInfo
            
                printer.present(animated: true, completionHandler: nil)
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    • 2016-06-10
    • 1970-01-01
    • 2014-04-17
    • 2020-08-05
    相关资源
    最近更新 更多