LM-Kit OneDocs2026.8.10lm-kit.com
Document Utilities

Document Search Highlight

Searches text in a document and returns a highlighted copy.#

POST/lmkit/v1/document-search-highlight

Performs layout-aware text search within a PDF or image document, then produces a highlighted copy with search results visually marked. For PDF input, adds highlight annotations and saves incrementally for maximum performance. For image input, draws semi-transparent rectangles over matches and outputs PNG. Supports three search modes: exact text, regular expression, and fuzzy (edit-distance) matching. When pre-computed page layouts are provided (from a prior OCR or layout analysis pass), they are used for search instead of the document's native text extraction, enabling highlighting on raster PDFs or images. The highlighted document is stored on the server and a file ID is returned. This is a pure document processing operation that does not require an AI model. If processing exceeds the configured timeout, returns 202 Accepted with a job_id. Poll GET /lmkit/v1/jobs/ for status and results.

Request body

application/json ·

PropertyTypeDescription
inputrequiredstring

The input document to search and highlight. When input_format is 'Base64EncodedFile', provide a base64-encoded file payload (supported: PDF, PNG, BMP, GIF, PSD, PIC, JPEG, PNM, HDR, TGA, WEBP, TIFF). When 'FileIdentifier', provide the file ID previously returned by the lmkit/v1/files/upload endpoint.

input_format

How the input is provided. Accepted values: 'Base64EncodedFile' or 'FileIdentifier'. 'Base64EncodedFile' expects a base64-encoded document or image file. 'FileIdentifier' references a file previously uploaded via lmkit/v1/files/upload. Defaults to 'Base64EncodedFile'.

queryrequiredstring

The search text or pattern. For 'Text' mode, an exact substring. For 'Regex' mode, a .NET regular expression pattern. For 'Fuzzy' mode, the approximate text to locate.

search_mode

The type of search to perform. 'Text': exact substring matching. 'Regex': regular expression matching. 'Fuzzy': approximate matching using Damerau-Levenshtein edit distance. Defaults to 'Text'.

case_sensitiveboolean

Whether the text search should be case-sensitive. Only applies to 'Text' mode. Defaults to false.

whole_wordboolean

When true, only matches bounded by non-word characters on both sides are returned. Only applies to 'Text' mode. Defaults to false.

regex_ignore_caseboolean

When true, the regex pattern ignores case. Only applies to 'Regex' mode. Defaults to true.

max_edit_distanceobject (int32)

Maximum Damerau-Levenshtein edit distance for fuzzy matching. Clamped to [1, 10]. Only applies to 'Fuzzy' mode. Defaults to 2.

min_scoreobject (double)

Minimum normalized fuzzy score in the range [0..1]. Only applies to 'Fuzzy' mode. Defaults to 0.75.

token_awareboolean

When true, discounts whitespace substitution costs in fuzzy matching. Only applies to 'Fuzzy' mode. Defaults to true.

normalize_whitespaceboolean

When true, collapses whitespace in document text before searching. Defaults to true.

ignore_diacriticsboolean

When true, removes diacritical marks (accents) before searching. Defaults to true.

ignore_punctuationboolean

When true, strips punctuation characters before searching. Defaults to false.

ignore_symbolsboolean

When true, strips symbol characters before searching. Defaults to false.

max_resultsobject (int32)

Maximum number of matches to return across all pages. Clamped to [1, 5000]. Defaults to 100.

context_charsobject (int32)

Number of characters of surrounding context to include in each match snippet. Clamped to [0, 1000]. Defaults to 40.

page_rangestring

An optional page range to search (e.g. "1-3", "1,3,5", "2-"). When empty or not specified, all pages are searched. Page numbers are 1-based.

highlight_colorobject (int32)[]

The highlight fill color as an RGBA array [R, G, B, A], each in [0, 255]. Defaults to semi-transparent yellow [255, 255, 0, 80].

border_widthobject (float)

The border width for PDF highlight annotations, in points. Set to 0 for no visible border. Defaults to 0.

render_zoomobject (double)

Zoom factor when rendering image output. Clamped to [0.25, 4.0]. Only applies to image-based documents. Defaults to 1.0.

page_layouts[]

Optional pre-computed page layouts from a prior OCR or layout analysis pass. When provided, their text elements are used for search instead of the document's native text extraction. This enables highlighting on raster PDFs or images whose text was obtained externally.

Responses

StatusTypeDescription
200

OK

202

Accepted

400

Bad Request

404

Not Found

500application/json

Internal Server Error

curl -X POST "$LMKIT_ONE_URL/lmkit/v1/document-search-highlight" \
  -H "Authorization: Bearer $LMKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": "",
  "input_format": "Base64EncodedFile",
  "query": "",
  "search_mode": "Text",
  "case_sensitive": false,
  "whole_word": false
}'