Marker Tutorial: Converting PDFs and Documents to Markdown for RAG Pipelines

# Tutorial Marker: Mengubah PDF dan Dokumen Menjadi Markdown untuk Pipeline RAG Dalam dunia AI dan data engineering, kemampuan mengekstrak teks dari dokumen PDF, EPUB, dan gambar menjadi format terst...

By Ruby Abdullah · · tutorial
MarkerPDFOCRRAGDocument Processing

Marker Tutorial: Converting PDFs and Documents to Markdown for RAG Pipelines

In the world of AI and data engineering, extracting text from PDF documents, EPUBs, and images into structured formats is a fundamental requirement. Marker is an open-source library by VikParuchuri that converts documents into high-quality Markdown with remarkable accuracy, including recognition of tables, mathematical formulas, and complex document layouts.

This tutorial covers how to use Marker comprehensively, from installation to integrating it into production RAG (Retrieval-Augmented Generation) pipelines.

Why Marker?

Before Marker, developers typically relied on PyPDF2, pdfminer, or Tesseract OCR for text extraction from PDFs. However, these tools often produce messy output, lose table formatting, and fail to recognize multi-column layouts.

Marker solves these problems with a different approach. The library uses a combination of deep learning models to:

  • Detect page layout (headers, footers, columns, tables)
  • Recognize text with Surya-based OCR
  • Convert tables into clean Markdown format
  • Process mathematical formulas into LaTeX
  • Handle multilingual documents

Marker supports PDF, EPUB, MOBI, and various image formats as input. The output is clean Markdown ready for indexing, RAG pipelines, or further analysis.

Installation

System Prerequisites

Marker requires Python 3.9 or later. For optimal performance, a GPU with CUDA is highly recommended, although CPU is also supported.

python --version

Make sure your Python version is at least 3.9.

Installation via pip

The easiest way to install Marker is using pip:

pip install marker-pdf

This will install Marker along with all required dependencies, including Surya models for OCR and layout detection.

Installation from Source

If you want the latest version or wish to contribute to development:

git clone https://github.com/VikParuchuri/marker.git

cd marker

pip install -e .

Installation with GPU Support

To enable GPU acceleration with CUDA:

pip install marker-pdf[gpu]

Make sure the CUDA toolkit is installed on your system. Verify with:

python -c "import torch; print(torch.cuda.isavailable())"

Model Download

When run for the first time, Marker will automatically download the required models from Hugging Face. These models include:

  • Layout detection model
  • OCR model (Surya)
  • Table recognition model
  • Mathematical formula conversion model

Total model size is approximately 2-3 GB. Ensure a stable internet connection during the first run.

Basic Usage

Single File Conversion via CLI

Marker provides an easy-to-use command-line interface:

markersingle /path/to/document.pdf /path/to/output/folder

This command generates a Markdown file in the output folder along with images extracted from the document.

Batch Conversion

To convert multiple documents at once:

marker /path/to/input/folder /path/to/output/folder

Marker will process all PDF, EPUB, and MOBI files in the input folder in parallel.

Using the Python API

For integration into Python applications, use the API directly:

from marker.converters.pdf import PdfConverter

from marker.models import createmodeldict

from marker.output import textfromrendered

Initialize converter with models

converter = PdfConverter(

artifactdict=createmodeldict(),

)

Convert document

rendered = converter("document.pdf")

Get Markdown text and metadata

text, metadata, images = textfromrendered(rendered)

print(text) # Markdown output

print(metadata) # Document metadata

Example Output

For instance, if you have a financial report PDF with tables, Marker will produce output like:

# Financial Report Q1 2026

Revenue Summary

| Category | Q1 2025 | Q1 2026 | Growth |

|----------|---------|---------|--------|

| Product A | $500K | $750K | 50% |

| Product B | $300K | $420K | 40% |

Related Articles

Docling: Smart Document Parsing for AI and RAG Pipelines

Docling: Document Parsing Cerdas untuk Pipeline AI dan RAG Dalam era AI generatif, kemampuan untuk mengekstrak informasi...

Complete Pinecone Tutorial: Vector Database for AI and Semantic Search

Tutorial Lengkap Pinecone: Vector Database untuk AI dan Semantic Search Pinecone adalah managed vector database yang dir...

Complete Tavily Tutorial: AI Search API for RAG and AI Agents

Tutorial Lengkap Tavily: AI Search API untuk RAG dan AI Agents Tavily adalah search API yang dirancang khusus untuk apli...

LangChain Tutorial: The Most Popular Framework for Building LLM Applications

Tutorial LangChain: Framework Paling Populer untuk Membangun Aplikasi LLM LangChain adalah framework open-source yang di...