Skip to content
ComPDF
DemoAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Guides

Custom Context Menu

Configure custom context menu items in Context Menu, then handle taps with onCustomContextMenuItemTapped.

onCustomContextMenuItemTapped(identifier, event) passes the custom item identifier separately. The second event argument does not contain identifier.

Callback Payloads

ContextSecond event argument
Screenshot{ image: string }; Base64 without a Data URI prefix. Android encodes PNG, while iOS encodes JPEG at quality 0.85.
Text selection{ text: string, rect: CPDFRectF, pageIndex: number }
Page long press{ point: { x: number, y: number }, pageIndex: number }
Annotation{ annotation: CPDFAnnotation }
Content editor{ editArea: CPDFEditArea }
Form field{ widget: CPDFWidget }

annotation, widget, and editArea are converted to SDK class instances. rect and point remain plain JavaScript objects. Image editing also uses the editArea key; there is no imageArea event key.

tsx
<CPDFReaderView
  ref={pdfReaderRef}
  document={samplePDF}
  configuration={configuration}
  onCustomContextMenuItemTapped={(identifier, event) => {
    const annotation = event.annotation as CPDFAnnotation | undefined;
    if (annotation) {
      console.log(identifier, annotation.type);
    }
  }}
/>

When displaying a screenshot, add the correct Data URI prefix in your application: data:image/png;base64, on Android or data:image/jpeg;base64, on iOS.

For custom toolbar actions, see Custom Toolbar Menu.