Skip to content
ComPDF
Guides

Edit Form Fields

Retrieve and edit the appearance and content of form fields.

Note that the properties of different form field types may not be entirely consistent.

The steps to edit a form field are as follows:

  1. Obtain the form object to be edited.

  2. Modify the form properties.

  3. Update the form appearance.

This example shows how to edit form fields:

java
CPDFTextWidget textWidget = (CPDFTextWidget) cpdfWidget;
textWidget.setFillColor(Color.RED);
textWidget.updateAp();
kotlin
val textWidget = myCPDFWidget as CPDFTextWidget
textWidget.setFillColor(Color.RED)
textWidget.updateAp()

ReaderView Synchronization

If the current PDF is being displayed via CPDFReaderView, and the target page is loaded or currently visible on screen, you need to use CPDFPageView to refresh the appearance of the corresponding form.

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

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

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

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