A command-line tool that converts Markdown files to PDF using CommonMark for parsing and iText for HTML-to-PDF rendering.
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.
gradlew.bat build # Windows
./gradlew build # Linux/macOSThe tool reads file.md from the project root and writes file.pdf:
gradlew.bat run # Windows
./gradlew run # Linux/macOSBuild the distribution once, then run directly:
gradlew.bat installDist # Windows
./gradlew installDist # Linux/macOSThis 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 # Windowsgradlew.bat test # Windows
./gradlew test # Linux/macOSThe 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)- CommonMark 0.27.0 — Markdown parser
- CommonMark GFM Tables 0.27.0 — GFM table extension
- iText html2pdf 6.3.0 — HTML to PDF conversion
- Kotlin 2.0.0, Gradle 8.14
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).