如何使用 PDFKit (Swift) 剪辑 PDFPage 之外的 PDFAnnotation 部分?

问题描述

我正在使用 PDFKit (Swift) 向 PDF 当前页面添加一个简单的 PDFAnnotion(Ink)。问题是当我在注释的某些部分位于页面边界之外的位置添加注释时,注释的部分不会被剪裁并显示在页面之外。我怎样才能摆脱注释的这个外部部分?我也附上了一张图片。这是代码

 private func createFinalAnnotation(path: UIBezierPath,page: PDFPage) -> PDFAnnotation {
  let border = PDFBorder()
  border.lineWidth = drawingTool.width
  let bounds = CGRect(x: path.bounds.origin.x - 5,y: path.bounds.origin.y - 5,width: path.bounds.size.width + 10,height: path.bounds.size.height + 10)
  var signingPathCentered = UIBezierPath()
  signingPathCentered.cgPath = path.cgPath
  signingPathCentered.moveCenter(to: bounds.center)
  let annotation = PDFAnnotation(bounds: bounds,forType: .ink,withProperties: nil)
  annotation.color = color.withAlphaComponent(drawingTool.alpha)
  annotation.border = border
  annotation.add(signingPathCentered)
  page.addAnnotation(annotation)
  return annotation
}

我正在使用此策略添加墨迹注释:Medium iOS PDF Ink Annotation

Issue with the annotation

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...