Skip to content
published Visibility internal Owner _ Approver _ Created _ Updated _

Markdown To PDF

Purpose

Convert any .md file to a styled .pdf using the Uvilo theme. Output PDF is placed in the same folder as the source .md file.

When to Use

  • User asks to convert a markdown file to PDF
  • User says “make a PDF of this .md” or “generate PDF from markdown”
  • Any request to produce a PDF from a .md file using the Uvilo brand style

Prerequisites

  • pandoc installed (via pypandoc-binary or system package)
  • weasyprint installed (pip install weasyprint)
  • System libraries: pango, glib, harfbuzz (for weasyprint)
  • Fontconfig configured with Uvilo fonts directory

Constants

SCRIPT=[[orgRepoRoot]]/Forge/Skills/Markdown_To_PDF/scripts/md2pdf.sh
CSS_FILE=[[orgRepoRoot]]/Forge/Skills/Markdown_To_PDF/Assets/uvilo.css
FONTS_DIR=[[orgRepoRoot]]/Uvilo/Assets/Fonts

How to Run

bash [[orgRepoRoot]]/Forge/Skills/Markdown_To_PDF/scripts/md2pdf.sh /path/to/document.md

What the Script Does

  1. Validates input file, tools, CSS, and fonts directory
  2. Derives output path — replaces .md with .pdf, same directory
  3. Generates PDF — via pandoc --pdf-engine weasyprint --css uvilo.css
  4. Runs from /tmp so pandoc can write temp files

Differences from uvilo_method_release

Simplified, general-purpose converter. Does not duplicate source, stamp versions, generate TOC, produce .docx, or create output subfolders.

Environment Setup (Cloud)

In the Railway/cloud environment, weasyprint requires system libraries not pre-installed. Setup:

# Install system libraries (Debian-slim)
apt-get update && apt-get install -y --no-install-recommends \
  pango glib harfbuzz

# Python venv with weasyprint + pandoc
python3 -m venv /tmp/pdf-venv
source /tmp/pdf-venv/bin/activate
pip install weasyprint pypandoc-binary

# Fontconfig
mkdir -p /tmp/fontconfig /tmp/fontcache
cat > /tmp/fontconfig/fonts.conf << 'EOF'
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
  <dir>[[orgRepoRoot]]/Uvilo/Assets/Fonts</dir>
  <cachedir>/tmp/fontcache</cachedir>
</fontconfig>
EOF

# Environment variables
export FONTCONFIG_FILE=/tmp/fontconfig/fonts.conf
export XDG_CACHE_HOME=/tmp/fontcache

Troubleshooting

Missing system libraries

  • Error: cannot load library 'libgobject-2.0-0'
  • Fix: Install pango/glib/harfbuzz (see Environment Setup)

Fontconfig errors

  • Error: Cannot load default config file
  • Fix: Set FONTCONFIG_FILE and XDG_CACHE_HOME (see Environment Setup)

pandoc temp file permission denied

  • Error: openTempFile: permission denied
  • Fix: Script runs from /tmp; ensure TMPDIR=/tmp is set

Missing fonts

  • Error: Fonts render as fallback sans-serif
  • Fix: Ensure FONTS_DIR exists and fontconfig points to it