I made the tool used in this post (PDF to Markdown on Apify), so I'm biased. I also used AI (Claude) to help write the code and this article. The Python input and the output fields below are checked against the Actor's published input schema and a real run on the NIST document.
If you build a "chat with your documents" app, the quality of your answers depends on the quality of your chunks. Raw text from a PDF loses tables and headings, so the search finds the wrong passages. Here is a simple way to get better chunks, in five steps.
Step 1: Convert the PDF to Markdown
Markdown is plain text that still shows headings, lists and tables. On Apify, open PDF to Markdown, paste a link to your PDF (or Word or PowerPoint file) and run it.
https://apify.com/tedock/doc-to-markdown?ref=devto
Or run it from Python with the Apify client:
from apify_client import ApifyClient client = ApifyClient("YOUR_APIFY_TOKEN") run = client.actor("tedock/doc-to-markdown").call( run_input={"urls": [{"url": "https://example.com/report.pdf"}]} ) items = client.dataset(run["defaultDatasetId"]).iterate_items() urls takes a list of links (plain strings also work). By default you get one row per document with its chunks; set outputMode to chunks to get one row per chunk, which is easier to load into a vector database.
Step 2: Look at what comes back
Each result has the Markdown for the whole document and a list of chunks. A chunk looks like this:
{ "text": "## 4. Experiments\n\n4.1. ImageNet Classification ...", "tokens": 399, "headings": ["Deep Residual Learning for Image Recognition", "4. Experiments"], "pageStart": 4, "pageEnd": 5, "chunkIndex": 18 } The chunks follow the document's headings, so a section stays together instead of being cut in the middle of a sentence. tokens is an estimate, so you can check it fits your embedding model.
Step 3: Embed the chunks
Use any embedding model you like. The tool does not care which one. The idea is the same:
texts = [] metadata = [] for item in items: for chunk in item["chunks"]: texts.append(chunk["text"]) metadata.append({ "headings": chunk["headings"], "pages": (chunk["pageStart"], chunk["pageEnd"]), }) # vectors = your_embedding_model.embed(texts) # store vectors + metadata in your vector database Step 4: Keep the heading path and page numbers
Store headings and the page numbers next to each vector. Two things get better right away:
- You can show "Section 4, pages 4-5" under each answer, so people can check it.
- You can add the heading path to the text you embed, which helps the search when a paragraph on its own is vague.
Step 5: Check one table by eye
Before you trust the output, open one table from your own document and compare it to the PDF. Here is a real one, Table 1 from the NIST Cybersecurity Framework 2.0.
Plain text copy:
Govern (GV) Organizational Context GV.OC Risk Management Strategy GV.RM Roles, Responsibilities, and Authorities GV.RR Converted:
| Function Category | Category Identifier | | --- | --- | | Govern (GV) Organizational Context | GV.OC | | Risk Management Strategy | GV.RM | | Roles, Responsibilities, and Authorities | GV.RR | Now every row has its code in its own column. It is not perfect: the first two columns of the original got merged into one cell. The data is all there, but you may want to clean that cell.
What to watch for
- Scanned PDFs (photos of pages) are read with OCR, English only. The result is plain paragraphs: tables in scans are not rebuilt and headings are not detected, and blurry scans can misread numbers.
- Tables that continue across two pages can split in two.
- Merged cells in complicated tables can come out as plain text.
- Cost: $0.003 per document (up to 100 pages), no start fee. Scanned pages cost $0.005 each on top. Failed downloads and unreadable scans are free. You can set a maximum cost per run and it stops before going over.
Send me a file that breaks it
If it gets one of your documents wrong, tell me on the Actor's issues page. I answer within a day, and real failures are the most useful thing you can send.
tedock

