Skip to content
ComPDF
Guides

Update Annotation Appearances

Annotations may include properties describing their appearance, such as annotation color or shape. However, these properties do not guarantee consistent display across different PDF readers. To address this issue, each annotation can define an appearance stream applied for rendering.

When modifying annotation properties, you must invoke the UpdateAp() method within the CPDFAnnotation class:

java
public boolean updateAp();

Setting a custom appearance stream for annotations is straightforward. This operation is commonly performed in stamp annotations, particularly because they don't have other properties. Stamp annotations used in this manner are often referred to as image annotations.

ReaderView Synchronization

If the PDF is currently displayed via CPDFReaderView and the target page is loaded or visible on the screen, you need to refresh the annotation appearance using CPDFPageView.

Only pages that are displayed or about to be displayed have a CPDFPageView. Always check for null.

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

if (pageView != null) {
    CPDFAnnotImpl annotationImpl = pageView.getAnnotImpl(annotation);
    annotationImpl.onAnnotAttrChange(); // Refresh annotation appearance
    pageView.invalidate();              // Redraw the page view
}
kotlin
val pageView = readerView.getChild(pageIndex) as? CPDFPageView

pageView?.let { view ->
    val annotationImpl = view.getAnnotImpl(annotation)
    annotationImpl.onAnnotAttrChange() // Refresh annotation appearance
    view.invalidate()                  // Redraw the page view
}