Picture yourself uploading a 50-page annual report, with two columns of text and a stack of financial tables, to a chatbot and asking one question: what was last year's revenue? In the bad case, the model makes up a number or insists the document never says.

The fault often lies in the input, and that matters to anyone building a custom chatbot or an internal knowledge base on retrieval-augmented generation (RAG), where the chatbot looks up passages in your documents before it answers. The PDF is where quality is lost first. MarkItDown, an open-source tool from Microsoft, repairs the easy cases and cuts the cost of every query, but dense layouts push it past its limits, and for those you need another tool or the PDF itself.


Simple parsers lose the thread across columns and tables

On screen, a PDF is perfectly structured. Read out naively, it often becomes unstructured text to a language model, because simple parsers, the programs that pull text out of a file, tend to read a page in the order the characters happen to be stored. With columns, headers and tables, the connections between them get lost.


Sending the PDF directly costs tokens for text and for page images

You can hand a PDF straight to a current Claude model through the API. According to Anthropic's documentation, the system extracts the text of each page and also converts the page into an image, so the model sees the words and the layout, charts included. That works well, and it has a price: Anthropic puts the text alone at typically 1,500 to 3,000 tokens per page (tokens are the chunks of text a model reads and bills by), depending on how dense the page is, with image costs added on top. For the 50-page report above, the text alone comes to 75,000 to 150,000 tokens before a single image is counted, and across long documents and many queries the total climbs quickly.


MarkItDown turns text-heavy files into lean Markdown on your own machine

Convert a text-heavy document to Markdown first, plain text with light markup for headings, lists and tables, and the token count usually falls well below that, since the page image drops out. How much you save depends heavily on the document, so measure it on your own files.

MarkItDown is a Python library from Microsoft, released under the MIT license, that converts PDF, Word, Excel and PowerPoint files into Markdown locally and without an API key:

from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("report.pdf")
print(result.markdown)

Headings, lists and tables survive as far as the source format allows, and with Office files that works very well.

The cleaner text pays off further down the pipeline. A model reading well-ordered text misreads less, though that does not rule out hallucinations. A knowledge base has to cut documents into passages, a step called chunking, and Markdown lets it split at headings and paragraph breaks instead of mid-sentence. Fewer tokens also mean a smaller API bill and shorter response times.


Columns, complex tables and scans are where MarkItDown stops

For PDFs, MarkItDown is mainly a text extractor. It builds on standard libraries such as pdfminer and does no AI-based layout analysis, so multi-column pages, complex tables and scanned documents without OCR (text recognition for scanned pages) can come out messy.

Two tools cover those cases. Docling, an open-source package that started at IBM Research Zurich, detects layout and table structure with its own AI models and runs locally, according to its authors. Azure Document Intelligence, Microsoft's cloud service, returns a layout analysis with Markdown output and plugs into MarkItDown.


Dense pages are better sent as PDF

Where charts, graphics or the layout itself carry the meaning, the model's visual processing has the edge. That gives you a workable rule: convert the text-heavy documents and hand the visually dense ones to the model as PDF.

Anyone who builds business-critical processes on PDFs should treat data preparation as a design decision. Run your own documents through each tool, compare what comes back with the originals, and keep the one that gives the best results.


Sources

The link has been copied!