NaviGator AI

Extract text from documents (OCR)

Turn scanned pages, photos of documents and PDFs into Markdown with NaviGator AI Toolkit

Optical character recognition (OCR) turns an image of a page into text you can search, edit and reuse. NaviGator AI Toolkit offers Jina OCR v1, a model built for documents. It returns clean Markdown in natural reading order, including headings, lists and tables. It can also read handwriting.

Use it for scanned forms, photographed pages, slides, receipts and PDFs without a text layer. For questions about an image, such as "what does this chart show?", use a model from Image understanding instead.

Before you begin

  • Create a key and set NAVIGATOR_TOOLKIT_API_KEY as described in Getting Started.
  • Confirm the documents' data classification is approved for the model. See data classifications.
  • Jina OCR v1 is released under the CC BY-NC 4.0 license, which does not permit commercial use.

How it works

Send one page image per request, together with a short instruction. The model returns that page as Markdown.

  • Images: send a PNG or JPEG of the page at a resolution where the text is easy to read.
  • PDFs: render each page as an image first, then send the pages one at a time. See Read a PDF.
  • Output length: set max_tokens to 4096 so long pages are not cut off.
  • Repeatability: set temperature to 0.

The instruction

Use the instruction recommended by Jina AI:

Transcribe the provided document image into a clean Markdown format, preserving the natural reading order.

For academic papers, Jina AI publishes a stricter instruction. It returns equations as LaTeX and tables as HTML. It also drops page headers, footers and figures. It is published on the model card.

Read one page

These examples read page.png from the current folder and print the Markdown.

IMAGE_B64=$(base64 < page.png | tr -d '\n')

curl -s https://api.navigator.ai.ufl.edu/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $NAVIGATOR_TOOLKIT_API_KEY" \
  -d @- <<EOF
{
  "model": "jina-ocr-v1",
  "max_tokens": 4096,
  "temperature": 0,
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "Transcribe the provided document image into a clean Markdown format, preserving the natural reading order."},
      {"type": "image_url", "image_url": {"url": "data:image/png;base64,$IMAGE_B64"}}
    ]
  }]
}
EOF

The Markdown is in choices[0].message.content of the JSON response. The command works on macOS and Linux.

For a JPEG, change image/png to image/jpeg in the data URL.

Use the Responses API

The same request can be sent through the Responses API. Chat Completions is the model's native interface; use Responses only when the rest of your application already does.

Check before relying on it: Responses API support for local models is limited, and image input through Responses is listed as unsupported for local models in the Responses API limitations. Test this request with your key first, and use Chat Completions if it returns an error.

IMAGE_B64=$(base64 < page.png | tr -d '\n')

curl -s https://api.navigator.ai.ufl.edu/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $NAVIGATOR_TOOLKIT_API_KEY" \
  -d @- <<EOF
{
  "model": "jina-ocr-v1",
  "max_output_tokens": 4096,
  "temperature": 0,
  "input": [{
    "role": "user",
    "content": [
      {"type": "input_text", "text": "Transcribe the provided document image into a clean Markdown format, preserving the natural reading order."},
      {"type": "input_image", "image_url": "data:image/png;base64,$IMAGE_B64"}
    ]
  }]
}
EOF

The Markdown is in the output item whose type is message, under content[0].text.

Read a PDF

This Python script renders each page of document.pdf, sends the pages one at a time and saves the result as document.md. It works on Windows, macOS and Linux.

Install the packages first:

python -m pip install openai pypdfium2 pillow
import base64
import io
import os
from pathlib import Path

import pypdfium2 as pdfium
from openai import OpenAI

PROMPT = (
    "Transcribe the provided document image into a clean Markdown format, "
    "preserving the natural reading order."
)

client = OpenAI(
    api_key=os.environ["NAVIGATOR_TOOLKIT_API_KEY"],
    base_url="https://api.navigator.ai.ufl.edu/v1",
)

pdf = pdfium.PdfDocument("document.pdf")
pages = []

for index in range(len(pdf)):
    # Render each page at twice the PDF's default resolution.
    image = pdf[index].render(scale=2).to_pil()
    buffer = io.BytesIO()
    image.save(buffer, format="PNG")
    image_b64 = base64.b64encode(buffer.getvalue()).decode()

    response = client.chat.completions.create(
        model="jina-ocr-v1",
        max_tokens=4096,
        temperature=0,
        messages=[
            {
                "role": "user",
                "content": [
                    {"type": "text", "text": PROMPT},
                    {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image_b64}"}},
                ],
            }
        ],
    )
    pages.append(response.choices[0].message.content)
    print(f"Page {index + 1} of {len(pdf)} done")

Path("document.md").write_text("\n\n".join(pages), encoding="utf-8")
print("Saved document.md")

A PDF that already contains selectable text does not need OCR. Copying or extracting its text is faster and exact.

Check the result

OCR output is a draft. Before relying on it:

  • compare numbers, names and dates with the original page
  • check that table rows and columns stayed aligned
  • confirm handwriting was read correctly
  • look for repeated or missing lines at page boundaries

On this page