pdf2md

module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: MIT

README

pdf2md - PDF to Markdown Converter

CI Release License

A fast, single-binary PDF to Markdown converter written in Go. Designed for AI engineers, researchers, and knowledge workers who need clean, structured Markdown from PDF documents.

How it Works

  • Single Binary - Zero dependencies, just download and run
  • Custom PDF Parser - Pure Go implementation, no CGO or external libraries required
  • Column Detection - Handles multi-column layouts (academic papers, newspapers)
  • Smart Layout Analysis - Preserves reading order and document structure
  • Header Detection - Automatically identifies H1-H6 based on font size or numbering
  • Code Block Detection - Identifies code blocks based on content patterns
  • List Detection - Handles bulleted and numbered lists
  • Privacy-First - Runs completely locally, no cloud API calls
  • Fast - Built in Go for high performance

Installation

From Source
go install github.com/fjacquet/pdf2md/cmd/pdf2md@latest
Build Locally
git clone https://github.com/fjacquet/pdf2md
cd pdf2md
go build -o pdf2md ./cmd/pdf2md

Usage

Convert a PDF to Markdown (output to stdout):

./pdf2md input.pdf

Save to a file:

./pdf2md input.pdf output.md

Architecture

pdf2md uses a modular pipeline architecture:

  1. PDF Parser (internal/pdf) - Custom pure Go PDF parser that handles:
    • Cross-reference table parsing
    • Object reading (dictionaries, streams, arrays)
    • Content stream interpretation
    • Font handling (CMap, Encodings)
  2. Extractor (internal/extractor) - Abstraction layer for text extraction
  3. Analyzer (internal/layout) - Detects columns, headers, and reading order
  4. Builder (internal/markdown) - Generates clean Markdown output
Current Implementation
  • Pure Go: Replaced go-fitz with a custom PDF parser implementation.
  • Robust: Handles various PDF versions and structures.
  • Extensible: Designed to support more PDF features in the future.

Roadmap

Phase 1: Core Parsing (Completed)
  • Custom PDF Reader & Parser
  • Content Stream Interpreter
  • Font Handling (Type1, TrueType, CMap)
  • Text Extraction
Phase 2: Layout Analysis (Completed)
  • Column detection
  • Header identification (H1-H6)
  • Reading order preservation
  • List detection
  • Code block detection
Phase 3: Visual Elements (Completed)
  • Table extraction and formatting (Basic implementation)
  • Image extraction to assets folder
  • Link extraction
  • Vector graphics extraction
Phase 4: Advanced (Planned)
  • OCR support for scanned PDFs
  • Configurable exclusion zones (headers/footers)
  • Custom formatting rules

Development

Project Structure
pdf2md/
├── cmd/pdf2md/          # Main CLI application
├── internal/
│   ├── pdf/             # Custom PDF parser implementation
│   ├── extractor/       # Extraction interface and implementations
│   ├── layout/          # Layout analysis and structure detection
│   ├── markdown/        # Markdown generation
│   ├── types/           # Shared types (TextBlock, etc.)
│   └── testdata/        # Test PDFs
└── go.mod
Running Tests
go test ./...

License

MIT License - See LICENSE file for details

Contributing

Contributions welcome! Please open an issue before submitting major changes.

Directories

Path Synopsis
cmd
benchmark command
Package main implements a benchmark tool for comparing pdf2md output against ground truth.
Package main implements a benchmark tool for comparing pdf2md output against ground truth.
pdf2md command
Package main provides the pdf2md command-line tool for converting PDF to Markdown.
Package main provides the pdf2md command-line tool for converting PDF to Markdown.
Package main provides an example of using pdf2md as a library.
Package main provides an example of using pdf2md as a library.
internal
extractor
Package extractor provides PDF content extraction functionality.
Package extractor provides PDF content extraction functionality.
layout
Package layout provides PDF document layout analysis functionality.
Package layout provides PDF document layout analysis functionality.
markdown
Package markdown provides Markdown generation from document elements.
Package markdown provides Markdown generation from document elements.
modelcache
Package modelcache provides a single source of truth for downloading, caching, and resolving ONNX models and the ONNX Runtime shared library.
Package modelcache provides a single source of truth for downloading, caching, and resolving ONNX models and the ONNX Runtime shared library.
ocr
Package ocr provides ONNX-based optical character recognition for scanned or image-only PDF pages.
Package ocr provides ONNX-based optical character recognition for scanned or image-only PDF pages.
onnx
Package onnx provides ONNX-based document layout detection using DocLayout-YOLO model.
Package onnx provides ONNX-based document layout detection using DocLayout-YOLO model.
pdf
Package pdf provides low-level PDF parsing and manipulation functionality.
Package pdf provides low-level PDF parsing and manipulation functionality.
render
Package render provides PDF-to-image rendering via go-pdfium.
Package render provides PDF-to-image rendering via go-pdfium.
types
Package types defines shared data structures used across pdf2md packages.
Package types defines shared data structures used across pdf2md packages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL