The problem
A PDF that looks clear to a person can produce text in the wrong order when extracted mechanically. Columns, headings, and tables may run together. Giving that output to an agent can make related statements look unrelated or lose the context of a number.
How NativePort helps
NativePort connects the PDF to a document reader that returns Markdown for each page. This gives the agent a cleaner starting point with useful structure preserved. Keep the page boundaries when you need citations or a way to check the source.
Technical implementation
Use Python 3 with requests installed (python -m pip install requests). Set NATIVEPORT_API_KEY in your environment to your NativePort key. Run the snippets on your server, where your key stays private.
Set DOCUMENT_URL to an HTTPS URL the document service can fetch, such as a time-limited file link. The example reads page 0 (the first page). Select only pages you need, up to 100 per request; split longer documents into batches. Send the URL, not inline file bytes.
import os
import requests
BASE = "https://api.nativeport.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['NATIVEPORT_API_KEY']}"}
payload = {
"document": {"type": "document_url", "document_url": os.environ["DOCUMENT_URL"]},
"pages": [0],
}
response = requests.post(BASE + "/mistral/v1/ocr", headers=HEADERS,
json=payload, timeout=120)
response.raise_for_status()
result = response.json()
from pathlib import Path
markdown = "\n\n".join(
f"<!-- Source page {page['index'] + 1} -->\n{page['markdown']}"
for page in result["pages"]
)
Path("document.md").write_text(markdown, encoding="utf-8")Chunk the Markdown by headings or page boundaries before indexing a long document. Keep the source URL and page numbers with each chunk. Rendering quality depends on the original layout. See the Mistral request policy for document URLs, page selection, and accepted options. OCR returns recognized content; check unclear scans against the source.
Tool costs
| Tool used in the example | Price per call |
|---|---|
| Mistral — OCR | $0.00422 / call (1 page) |
Prices in USD. Usage-based tools have no fixed per-call price. View pricing.
Let your agent build it
You don’t need to write this code yourself. Copy this page’s link and paste it into your agent. Ask it to follow the guide and implement the feature for you.