在iOS 11中,我有一个允许注释PDF的PDFView
控制器实现,以及使用PDFAnnotationSubtypeInk
let page : PDFPage = ...
let points : [CGPoint] = ...
let path = UIBezierPath()
for x in 0..<points.count {
let point = self.pdfView.convert(points[x], to: page)
if x == 0 {
path.move(to: point)
}else{
path.addLine(to: point)
}
}
let border = PDFBorder()
border.style = .solid
border.lineWidth = 2.0
let drawAnnotation = PDFAnnotation(bounds: page.bounds(for: .mediaBox), forType: .ink, withProperties: nil)
drawAnnotation.backgroundColor = .yellow
drawAnnotation.interiorColor = .yellow
drawAnnotation.fontColor = .yellow
drawAnnotation.color = .yellow
drawAnnotation.border = border
drawAnnotation.add(path)
page.addAnnotation(drawAnnotation)
当我调用持久性代码
时 if let path = self.pdfDocumentPath, let document = self.pdfDocument {
if !document.write(toFile: path){
NSLog("Failed to save PDF")
}
}
一切都在理论上有效,PDF被保存到磁盘......但是在下一次从磁盘重新加载时,我的注释无处可见。其他类型的注释正确保存(即文本和突出显示)
看起来UIBezierPaths永远不会从磁盘上恢复。在重新加载的PDFAnnotation
中找不到UIBezierPath我做错了吗?我错过了什么吗?
PS:我很抱歉Ruby开发人员在Ruby软件包上寻找问题/答案,称为PDFKit ... iOS iOS也有一个名为PDFKit的软件包...对不起任何困惑。答案 0 :(得分:2)
我在这个问题上遇到了问题。注释被保存,但UIBezierPath没有(及其所有点)
因此,当我将PDF写回磁盘时,我会浏览所有页面和所有注释,并找到具有UIBezierPath的注释,并将CGPoints序列化为JSON到PDFAnnotation content
属性中。
当重新加载相同的PDF时,我做了完全相同的事情,它遍历所有页面,找到.ink注释,反序列化点,并在注释上添加UIBezierPath。
答案 1 :(得分:1)
Apple修复了iOS 12中的此错误。 3425 [ main] DEBUG ls.rest.jersey.JerseyRestUtils -
Posting to https://api.blockcypher.com/v1/btc/test3/txs/new?token=mytoken: {"double_spend":false,"inputs":[{"addresses":["mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"]}],"outputs":[{"value":30000,"addresses":["mzF8NP6rHYG9ehVPYSJBFygu6LSYVqZLZg"]}]}
5339 [ main] INFO ockcypher.utils.sign.SignUtils - Pushing Pub key for input
5382 [ main] DEBUG ls.rest.jersey.JerseyRestUtils - Posting to https://api.blockcypher.com/v1/btc/test3/txs/send?token=mytoken: {"tx":{"hash":"b37e8f5dfa909876fe636c07db13a65ea6671ea723847f2e58815e6357200dcb","block_height":-1,"addresses":["mzF8NP6rHYG9ehVPYSJBFygu6LSYVqZLZg","mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"],"total":4219700,"fees":10300,"relayed_by":"78.128.153.1","received":"2018-09-18T14:37:52.357270154Z","ver":1,"vin_sz":1,"vout_sz":2,"confirmations":0,"preference":"high","double_spend":false,"inputs":[{"prev_hash":"68553b72dad64595bd2052547fcbe84a17e3966a01386b4caefb4518324cf2f9","output_index":0,"output_value":4230000,"addresses":["mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"],"script_type":"pay-to-pubkey-hash"}],"outputs":[{"value":30000,"script":"76a914cd6c24f57b38917f2066b342147a3802d0a2f6f788ac","addresses":["mzF8NP6rHYG9ehVPYSJBFygu6LSYVqZLZg"],"script_type":"pay-to-pubkey-hash"},{"value":4189700,"script":"76a91450e47d76f6f5dfe1de7de1f19e40afaefbfc008c88ac","addresses":["mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"],"script_type":"pay-to-pubkey-hash"}]},"tosign":["936678acb668bbe3055d98daf2bf43f7fd8c45e4948c9db01eca16759cbafc26"],"signatures":["3045022100c93d97a73c19c96a521c88d05ec1e11405611dd82407461a5a27dabf2d3d92540220574d453f707f3c40c862e8a1fd8a43c08a68e970fceaee21406aae75172ff137"],"pubkeys":["04a1cfb3e4c4088a4b8a30e09cd2e2ad0503948edab552dbe6550979fb77d3808fea0add24063d1249f2e54ec4dd01308961426f43b83393d367ac529fa8bbed9d"]}
Exception in thread "main" BlockCypherException{message=Bad Request, status=400, blockCypherError=[Error{error='Error validating generated transaction: Error running script for input 0 referencing 68553b72dad64595bd2052547fcbe84a17e3966a01386b4caefb4518324cf2f9 at 0: Script was NOT verified successfully.'}], exception=null}
at com.blockcypher.utils.rest.jersey.JerseyRestUtils.getBlockCypherException(JerseyRestUtils.java:90)
at com.blockcypher.utils.rest.jersey.JerseyRestUtils.post(JerseyRestUtils.java:33)
at com.blockcypher.utils.rest.jersey.JerseyRestUtils.post(JerseyRestUtils.java:50)
at com.blockcypher.utils.rest.RestUtils.post(RestUtils.java:20)
at com.blockcypher.service.TransactionService.postTransaction(TransactionService.java:59)
at com.blockcypher.service.TransactionService.sendTransaction(TransactionService.java:133)
at _test.sendBtc(_test.java:46)
at _test.main(_test.java:27)
已正确填充。
从11.2-11.4之间的某个版本开始(我没有机会进行验证,但是它无法在11.1中正常工作,并且不能在11.4+中工作),可以使用PDFAnnotation.paths
方法PDFAnnotation
正确渲染墨水注释。
注意,在iOS 12.0中,Apple中断了drawWithBox:inContext:
(从磁盘保存并重新加载PDFDocument后,alpha始终等于1)。可以通过使用上述方法在上下文中绘制注释来修复。