Skip to content
ComPDF
Guides

更新注释外观

注释可能包含描述其外观的属性,例如注释颜色或形状。但是,这些并不能保证注释在不同的PDF阅读器中显示相同。为了解决这个问题,每个注释可以定义一个应用于渲染注释的外观流。

当您修改注释属性时,必须调用CPDFAnnotation类中的updateAp()方法。

java
public boolean updateAp();

设置注释的自定义外观流非常容易。通常在图章注释中会进行这一操作,因为它们没有其他属性。以这种方式使用的图章注释通常被称为图像注释。

ReaderView 同步

如果当前 PDF 正在通过 CPDFReaderView 显示,并且目标页已加载或正在屏幕中显示, 需要使用CPDFPageView刷新对应的注释外观。

仅已显示或即将显示的页面才会存在 CPDFPageView,请务必判空。

java
CPDFPageView pageView = (CPDFPageView) readerView.getChild(pageIndex);

if (pageView != null) {
  CPDFAnnotImpl annotationImpl = pageView.getAnnotImpl(annotation);
  annotationImpl.onAnnotAttrChange();
  pageView.invalidate();
}
kotlin
val pageView = readerView.getChild(pageIndex) as? CPDFPageView

pageView?.let { view ->
    val annotationImpl = view.getAnnotImpl(annotation)
    annotationImpl.onAnnotAttrChange()
    view.invalidate()
}