我在 Swift 4.2 中构建 iOS 应用程序,可以对 PDF 文件进行签名。但是如果将签名嵌入为 PDFAnnotation,它可以在苹果的 Preview 应用程序或其他可以编辑 pdf 的应用程序中进行编辑。如何禁用编辑 PDFAnnoations ?
“签名”是由 UIImage 创建的,它转换了手写 beizerpaths。
class SignatureAnnotation: PDFAnnotation {
var image: UIImage!
init(with image: UIImage!, forBounds bounds: CGRect, withProperties properties: [AnyHashable : Any]?) {
super.init(bounds: bounds,
forType: PDFAnnotationSubtype.freeText,
withProperties: properties)
self.image = image
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
override func draw(with box: PDFDisplayBox, in context: CGContext) {
guard let cgImage = self.image.cgImage else { return }
context.draw(cgImage, in: self.bounds)
}
}
func embedSignatureToPDF() {
let page = pdfView.currentPage
let signatureAnnotation = SignatureAnnotation(with: signature, forBounds: signatureRect, withProperties: nil)
page.addAnnotation(signatureAnnotation)
}