Composables

usePdfKitSearch

Text search with highlighting.

Provides full-text search functionality with match highlighting.

Usage

const {
  searchQuery,
  matches,
  currentMatchIndex,
  currentMatch,
  totalMatches,
  hasMatches,
  isSearching,
  searchOptions,
  search,
  nextMatch,
  prevMatch,
  clearSearch,
  toggleCaseSensitive,
  toggleWholeWords,
} = usePdfKitSearch()

Return Values

PropertyTypeDescription
searchQueryRef<string>Current search query
matchesRef<SearchMatch[]>Array of search matches
currentMatchIndexRef<number>Index of current match (-1 when none)
currentMatchComputedRef<SearchMatch | null>Current match object
totalMatchesComputedRef<number>Total number of matches
hasMatchesComputedRef<boolean>Whether any match exists
isSearchingRef<boolean>Search in progress
searchOptionsRef<SearchOptions>Current search options
search(pdfDoc, query, options?) => Promise<void>Perform search on a PDF document
nextMatch() => voidGo to next match
prevMatch() => voidGo to previous match
clearSearch() => voidClear search results
toggleCaseSensitive() => voidToggle case sensitivity
toggleWholeWords() => voidToggle whole words

SearchMatch Interface

interface SearchMatch {
  pageIndex: number
  matchIndex: number
  text: string
}

SearchOptions

OptionTypeDefaultDescription
caseSensitivebooleanfalseMatch case exactly
wholeWordsbooleanfalseMatch whole words only

Example

<template>
  <div class="flex items-center gap-2">
    <UInput 
      v-model="query" 
      placeholder="Search..." 
      @keyup.enter="performSearch"
    />
    <span v-if="hasMatches">
      {{ currentMatchIndex + 1 }} / {{ totalMatches }}
    </span>
    <UButton @click="prevMatch">Prev</UButton>
    <UButton @click="nextMatch">Next</UButton>
    <UButton @click="clearSearch">Clear</UButton>
  </div>
</template>

<script setup>
const query = ref('')

const {
  matches,
  currentMatchIndex,
  hasMatches,
  totalMatches,
  search,
  nextMatch,
  prevMatch,
  clearSearch,
} = usePdfKitSearch()

// You need a PDFDocumentProxy instance, e.g. from usePdfKitDocument()
const { pdfDoc } = usePdfKitDocument()

async function performSearch() {
  await search(pdfDoc.value, query.value)
}
</script>
The search function requires a loaded PDFDocumentProxy instance as its first argument. Pair it with usePdfKitDocument to get the document instance.
Copyright © 2026