PDF to Markdown with Granite Docling V2

Convert the same one-page PDF in the official playground or on a CUDA machine, then compare the Markdown with the original page.

Download workshop-supplies.pdf

Convert in the playground

  1. Open the official Granite Docling V2 Playground and drop workshop-supplies.pdf onto the viewer. The live upload control accepts PDF, PNG, JPEG, BMP, GIF, TIFF and WebP.
  2. Open Advanced. Choose Granite Docling V2 2B from the model menu, which also offers a 500M variant. Set the prompt to <doclang> for the whole page and select Convert. Uploading can start conversion automatically, so wait for it to finish before rerunning with these settings.
  3. When conversion finishes, choose Download and select Markdown. Open the downloaded .md file as text and in a Markdown preview that supports pipe tables.

Convert locally with Transformers

You need Poppler's pdftoppm, Python 3.12 or later, and a CUDA-capable NVIDIA GPU with BF16 support. Install CUDA-enabled PyTorch and the matching torchvision build for your platform. From the folder containing the PDF, render page 1 and install the Python dependencies in a virtual environment.

pdftoppm -f 1 -l 1 -r 200 -png -singlefile workshop-supplies.pdf page
python -m venv .venv
source .venv/bin/activate
python -m pip install "transformers==5.23.0" torch torchvision pillow accelerate "docling-core==2.108.0"
python -c "import torch; assert torch.cuda.is_available() and torch.cuda.is_bf16_supported()"

Save this as convert.py and run python convert.py. The processor builds the prompt from page.png. Decode only the newly generated tokens and keep special tokens because they carry DocLang tags and positions. The Docling deserializer reads that structure when it exports Markdown.

import torch
from PIL import Image
from transformers import AutoModelForImageTextToText, AutoProcessor
from docling_core.transforms.deserializer.doclang import DocLangDocDeserializer

checkpoint = "ibm-granite/granite-docling-v2-2b"
processor = AutoProcessor.from_pretrained(checkpoint)
model = AutoModelForImageTextToText.from_pretrained(
    checkpoint, dtype=torch.bfloat16, device_map="cuda"
)

with Image.open("page.png") as page:
    image = page.convert("RGB")

messages = [{"role": "user", "content": [
    {"type": "image", "image": image},
    {"type": "text", "text": "<doclang>"},
]}]
inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
).to(model.device, dtype=torch.bfloat16)

output = model.generate(**inputs, max_new_tokens=16384, do_sample=False)
generated = output[0, inputs["input_ids"].shape[1]:]
doclang = processor.decode(generated, skip_special_tokens=False)
doclang = doclang.removesuffix(processor.tokenizer.eos_token)

document = DocLangDocDeserializer().deserialize_str(doclang)
document.save_as_markdown("workshop-supplies.md")

The sample rendered with Poppler 25.03.0. The Markdown export was checked with Python 3.13.5, docling-core 2.108.0, and doclang 0.10.1 using handwritten DocLang for the sample. Local model inference requires a CUDA run. The playground accepted the PDF, but its ZeroGPU quota blocked inference during verification.

Check table cells and reading order

Original PDF
Workshop supplies page with Packing list, a three-column table, and Handoff.
Local Docling export of handwritten DocLang
# Workshop supplies

## Packing list

Pack the items before Friday.

| Item      |   Quantity | Pickup    |
|-----------|------------|-----------|
| Markers   |         12 | Cabinet A |
| Notebooks |          8 | Cabinet B |

## Handoff

Leave the packed box at the front desk.

The export pads the table cells with spaces and uses more dashes in the separator row than the reference. Those changes keep the same table when rendered. The title uses one # and both section headings use two, as in the reference.

  • Headers and rows. Check for Item, Quantity, and Pickup in that order, with exactly two data rows under the header. Read across each row. Markers should have 12 and Cabinet A, and Notebooks should have 8 and Cabinet B.
  • Heading levels and order. Start with Workshop supplies as the title. Packing list should be a section heading, followed by “Pack the items before Friday.” and the table. Handoff should be at the same level as Packing list, followed by “Leave the packed box at the front desk.”
  • Fix and recheck. Move a misplaced cell value between the correct pair of pipes, keeping three cells on each row and three entries on the separator line. Move a misplaced heading, paragraph, or table as a complete block and leave blank lines around the block. Adjust the number of # markers if a heading has the wrong level. Reopen the rendered preview and check the row pairings and section order again against the PDF.

Sources