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

PDF OCR

Creates a searchable PDF from an image or PDF by overlaying invisible OCR text.#

POST/lmkit/v1/pdf-ocr

Performs Optical Character Recognition on the input document or image and produces a searchable PDF with invisible text overlaid on each page. Accepts any image format (PNG, JPEG, TIFF, BMP, WEBP, etc.) or an existing PDF. For PDF inputs, pages that already contain selectable text can be skipped or re-OCRed depending on text_page_handling. Supports page range selection for multi-page inputs, configurable PDF version (including PDF/A archival formats), image compression settings, and parallel processing for large documents. The output PDF is stored on the server and a file ID is returned. Use the file ID to download the result or pass it to other endpoints (pdf-search, document-to-markdown, pdf-layout) using the 'FileIdentifier' input format. If processing exceeds the configured timeout, returns 202 Accepted with a job_id. To force immediate async processing, include the 'Prefer: respond-async' HTTP header; the endpoint will always return 202 Accepted regardless of the timeout setting. Poll GET /lmkit/v1/jobs/ for status and results. While the job is processing, the polling response includes 'progress_current' and 'progress_total' fields indicating the number of pages processed so far and the total page count. Returns 422 Unprocessable Entity with an ErrorResponse body if the input file cannot be processed. The 'error' field contains one of: 'password_required' (encrypted PDF), 'invalid_format' (not a valid PDF), 'unsupported_security' (unsupported encryption), 'page_error' (content error).

Request body

application/json ·

PropertyTypeDescription
inputrequiredstring

The input document or image to convert into a searchable PDF. 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'.

page_rangestring

An optional page range to process (e.g. "1-3", "1,3,5", "2-"). When empty or not specified, all pages are processed. Page numbers are 1-based. For single-image inputs this is ignored.

text_page_handling

Controls how pages that already contain selectable text are handled. 'Skip' (default) preserves existing text pages as-is and only OCRs image-only pages. 'ForceOcr' re-OCRs every page regardless of existing text content.

text_detection_strategy

The strategy used to determine whether a page already contains text. 'TextOnly' (default) considers a page as having text only if it contains text-rendering objects. 'HasText' considers a page as having text if any extractable text content exists.

pdf_version

The target PDF version for the output file. 'Pdf17' (default, ISO 32000-1), 'Pdf14', 'Pdf15', 'Pdf16', 'PdfA1b' (ISO 19005-1 archival), 'PdfA2b' (ISO 19005-2 archival), 'PdfA3b' (ISO 19005-3 archival).

image_encoding

The compression method for color and grayscale images embedded in the output PDF. 'Jpeg' (default) uses lossy DCT compression for smaller files. 'Deflate' uses lossless FlateDecode compression for maximum quality.

binary_image_encoding

The compression method for binary (1-bit black and white) images in the output PDF. 'CcittGroup4' (default) uses CCITT Group 4 fax compression, optimal for scanned documents. 'Deflate' uses lossless FlateDecode compression.

jpeg_qualityobject (int32)

JPEG compression quality (1 to 100) when image_encoding is set to 'Jpeg'. Higher values produce better image quality at the cost of larger file size. Defaults to 70.

save_options

Controls how the output PDF is saved when the input is a PDF. 'None' (default) performs a full document rewrite. 'Incremental' appends changes, preserving digital signatures. 'RemoveSecurity' strips encryption from the output.

languages[]

An optional list of languages for OCR recognition. When not specified, the server's default language is used. Multiple languages can be specified for documents mixing scripts (e.g. ['English', 'French']). Supported values: Arabic, Armenian, Bulgarian, ChineseSimplified, ChineseTraditional, Croatian, Czech, Danish, Dutch, English, Finnish, French, German, Hebrew, Hindi, Hungarian, Indonesian, Italian, Japanese, Korean, ModernGreek, Norwegian, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Spanish, Swedish, Thai, Turkish, Ukrainian, Vietnamese.

detect_orientationboolean

Whether to enable automatic page orientation detection. When enabled, the engine detects if a page is rotated (90°, 180°, or 270°) and corrects it before text recognition. When not specified, the server's default setting is used.

Responses

StatusTypeDescription
200

OK

202

Accepted

400

Bad Request

404

Not Found

422

Unprocessable Entity

500application/json

Internal Server Error

curl -X POST "$LMKIT_ONE_URL/lmkit/v1/pdf-ocr" \
  -H "Authorization: Bearer $LMKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": "",
  "input_format": "Base64EncodedFile",
  "page_range": "",
  "text_page_handling": "Skip",
  "text_detection_strategy": "TextOnly"
}'