我有同样的问题。但是我可以通过使用Swift的函数将html转换为属性文本,然后对属性文本使用UISimpleTextPrintFormatter来解决它。
我的原始代码:
let formatter = UIMarkupTextPrintFormatter(markupText: htmlString)
formatter.perPageContentInsets = UIEdgeInsets(top: 70.0,left: 60.0,bottom: 70.0,right: 60.0)
printController.printFormatter = formatter
printController.present(animated: true,completionHandler: nil)
在Catalyst(和iOS)上工作:
guard let printData = htmlString.data(using: String.Encoding.utf8) else { return }
do {
let printText = try NSAttributedString(data: printData,options: [.documentType: NSAttributedString.DocumentType.html,.characterEncoding: String.Encoding.utf8.rawValue],documentAttributes: nil)
let formatter = UISimpleTextPrintFormatter(attributedText: printText)
formatter.perPageContentInsets = UIEdgeInsets(top: 70.0,right: 60.0)
printController.printFormatter = formatter
printController.present(animated: true,completionHandler: nil)
} catch {
print(error)
}
但是,与在iOS上相比,NSAttributedString(data:)对您在Catalyst上抛出的内容似乎更敏感。例如,我在使用iOS的表格上是否遇到过问题?因此,这不是一个完美的解决方案。
本文链接:https://www.f2er.com/3068881.html