PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
ComPDFKit_Tools provides a unified event dispatch mechanism via CPDFCustomEventCallbackHelper for listening to custom button clicks, annotation interaction interceptions, and other events.
CPDFCustomEventCallbackHelper.getInstance().addCustomEventCallback(extraMap -> {
String eventType = extraMap.get(
CPDFCustomEventField.CUSTOM_EVENT_TYPE).toString();
// Handle based on event type
});CPDFCustomEventCallbackHelper.getInstance().addCustomEventCallback { extraMap ->
val eventType = extraMap[CPDFCustomEventField.CUSTOM_EVENT_TYPE].toString()
// Handle based on event type
}@Override
protected void onDestroy() {
super.onDestroy();
CPDFCustomEventCallbackHelper.getInstance().removeCustomEventCallback(this);
}override fun onDestroy() {
super.onDestroy()
CPDFCustomEventCallbackHelper.getInstance().removeCustomEventCallback(this)
}Triggered when a custom toolbar button is tapped.
| Field | Value / Description |
|---|---|
CUSTOM_EVENT_TYPE | CPDFCustomEventType.TOOLBAR_ITEM_TAPPED |
identifier | Unique identifier of the button |
if (CPDFCustomEventType.TOOLBAR_ITEM_TAPPED.equals(eventType)) {
String identifier = extraMap.get("identifier").toString();
switch (identifier) {
case "custom_download":
// Handle download button tap
break;
}
}if (CPDFCustomEventType.TOOLBAR_ITEM_TAPPED == eventType) {
when (extraMap["identifier"].toString()) {
"custom_download" -> {
// Handle download button tap
}
}
}See Custom Toolbar Items for details.
Triggered when a custom context menu item is tapped.
| Field | Value / Description |
|---|---|
CUSTOM_EVENT_TYPE | CPDFCustomEventType.CONTEXT_MENU_ITEM_TAPPED |
IDENTIFIER | Unique identifier of the menu item |
ANNOTATION | Associated annotation object (may be null) |
if (CPDFCustomEventType.CONTEXT_MENU_ITEM_TAPPED.equals(eventType)) {
String identifier = extraMap.get(CPDFCustomEventField.IDENTIFIER).toString();
CPDFAnnotation annotation = (CPDFAnnotation) extraMap.get(
CPDFCustomEventField.ANNOTATION);
// Handle based on identifier
}if (CPDFCustomEventType.CONTEXT_MENU_ITEM_TAPPED == eventType) {
val identifier = extraMap[CPDFCustomEventField.IDENTIFIER].toString()
val annotation = extraMap[CPDFCustomEventField.ANNOTATION] as? CPDFAnnotation
// Handle based on identifier
}See Context Menu for details.
When the corresponding intercept*Action in annotationsConfig is set to true, tapping an annotation triggers an event instead of executing the default behavior.
| Intercept Config | Event Description |
|---|---|
interceptNoteAction: true | Intercept note annotation tap |
interceptLinkAction: true | Intercept link annotation tap |
When the corresponding intercept*Action in formsConfig is set to true, tapping a form control triggers an event (only supported for ListBox, ComboBox, and PushButton).
| Intercept Config | Event Description |
|---|---|
interceptListBoxAction: true | Intercept list box tap |
interceptComboBoxAction: true | Intercept combo box tap |
interceptPushButtonAction: true | Intercept push button tap |
| Constant | Description |
|---|---|
CUSTOM_EVENT_TYPE | Event type identifier |
IDENTIFIER | Unique identifier of custom button/menu |
ANNOTATION | Associated annotation object |
| Constant | Description |
|---|---|
TOOLBAR_ITEM_TAPPED | Toolbar button tap event |
CONTEXT_MENU_ITEM_TAPPED | Context menu item tap event |
onDestroy() to avoid memory leaksCUSTOM_EVENT_TYPE in callbacks, as different events may share the same callbackextraMapPage coordinates and tap consumption use IReaderViewCallback, not CPDFCustomEventCallbackHelper. With Tools, get the internal reader on the main thread and follow Reader Interaction Events to register and remove a listener:
CPDFReaderView readerView = pdfView.getCPdfReaderView();
readerView.setReaderViewCallback(readerCallback);Remove the same listener instance before destroying the reader view:
readerView.removeReaderViewCallback(readerCallback);pdfView is the Tools reader view; readerCallback implements onPageTap(PointF). Returning true suppresses every listener's legacy document-area callback for that page tap, avoiding fullscreen or toolbar toggles. Page gaps and the background outside pages retain legacy behavior.
The document modification flag belongs to CPDFDocument. See Document Modification State.