Skip to content

Latest commit

 

History

History
84 lines (55 loc) · 2.61 KB

File metadata and controls

84 lines (55 loc) · 2.61 KB

Markdown to PDF converter (Kotlin)

A command-line tool that converts Markdown files to PDF using CommonMark for parsing and iText for HTML-to-PDF rendering.

Status

Working. The converter handles headings, emphasis/bold, ordered and unordered lists, nested lists, blockquotes, fenced and inline code, links, GFM tables, horizontal rules, and inline HTML.

A JUnit 5 test suite with 14 tests verifies all supported features through the full conversion pipeline.

Some advanced Markdown features are not yet implemented. Pull requests are welcome.

Usage

Build

gradlew.bat build        # Windows
./gradlew build           # Linux/macOS

Run via Gradle

The tool reads file.md from the project root and writes file.pdf:

gradlew.bat run           # Windows
./gradlew run             # Linux/macOS

Run standalone (without Gradle)

Build the distribution once, then run directly:

gradlew.bat installDist   # Windows
./gradlew installDist     # Linux/macOS

This creates a standalone launcher with all dependencies in build/install/markdownToPDF2/. Run it from the project root (where file.md lives):

build/install/markdownToPDF2/bin/markdownToPDF2         # Linux/macOS (bash)
build\install\markdownToPDF2\bin\markdownToPDF2.bat     # Windows

Test

gradlew.bat test          # Windows
./gradlew test            # Linux/macOS

Programmatic use

The converter exposes two functions in com.jimandreas:

// Convert markdown text to a full HTML document with CSS styling
val html: String = convertMarkdownToHtml(markdownText)

// Convert a markdown file directly to PDF
convertMarkdownFileToPdf(inputFile, outputFile)

Dependencies

Background

The original code was written by Grok 4 Fast. Table formatting was added through iteration. The "ultimate" Markdown test file from StackOverflow was used for validation — some edge cases remain unhandled.

The test suite, Main.kt refactoring, and project configuration were contributed by Claude (Anthropic).

References