Skip to content

Text Selection

Takashi Kawasaki edited this page Dec 17, 2024 · 2 revisions

The following fragment uses PdfViewerParams.enableTextSelection to enable text selection feature:

PdfViewer.asset(
  'assets/test.pdf',
  params: PdfViewerParams(
    enableTextSelection: true,
    ...
  ),
  ...
),

If you want to handle text selection changes, you can use PdfViewerParams.onTextSelectionChange like the following fragment:

PdfViewer.asset(
  'assets/test.pdf',
  params: PdfViewerParams(
    enableTextSelection: true,
    onTextSelectionChange: (selections) {
      ...
    },
    ...
  ),
  ...
),

selections is a list of PdfPageText objects.

Further Text Selection Customization

Instead of using PdfViewerParams.enableTextSelection, you can also use PdfViewerParams.selectableRegionInjector to inject your custom SelectionArea or SelectableRegion:

PdfViewer.asset(
  'assets/test.pdf',
  params: PdfViewerParams(
    selectableRegionInjector: (context, child) {
      // Your customized SelectionArea
      return SelectionArea(
        child: child,
        ...
      );
    }
  ),
  ...
),