brewdoc:md-to-pdf
Converts Markdown to professional PDF. Two engines - reportlab (lightweight) or weasyprint (full CSS). Style customization, test mode, dependency management. Triggers - pdf, md to pdf, markdown to pdf, convert pdf, generate pdf.
What this skill does
# MD to PDF
Converts Markdown files to professional PDF using one of two rendering engines.
## Step 0: Parse Arguments
Parse `$ARGUMENTS` to determine mode and components.
| Component | Required | Description |
|-----------|:--------:|-------------|
| `md_file` | per mode | Path to `.md` file |
| `--engine` | No | `reportlab` or `weasyprint` (overrides saved config) |
| `custom_prompt` | No | Last argument in double quotes = LLM preprocessing instructions |
**Mode detection rules:**
| Condition | Mode |
|-----------|------|
| Empty or `help` | HELP |
| `styles` or `config` | STYLES |
| `test` | TEST |
| Path to `.md` file + quoted string at end | CONVERT+PROMPT |
| Path to `.md` file (no quoted string) | CONVERT |
Extract `--engine <name>` from anywhere in arguments if present. Remove it before further parsing.
## Step 1: Dependency Check
Determine the target engine (from `--engine` flag, saved config, or default `reportlab`).
**EXECUTE** using Bash tool:
```bash
bash "${CLAUDE_SKILL_DIR}/scripts/check_deps.sh" check ENGINE_NAME 2>&1; echo "EXIT_CODE=$?"
```
Replace `ENGINE_NAME` with the target engine.
**If output contains `MISSING_PIP` or `MISSING_SYSTEM`:**
Use `AskUserQuestion` presenting the engine comparison table:
| Feature | reportlab | weasyprint |
|---------|-----------|------------|
| Install | pip only | pip + brew |
| Quality | Good | Excellent |
| Speed | Fast | Moderate |
| Images | Basic | Full |
| CSS Styling | No | Yes |
| Code highlight | No | Yes (Pygments) |
Options:
- "Install ENGINE_NAME dependencies"
- "Switch to OTHER_ENGINE" (if the other engine is available)
- "Cancel"
If user chooses install, **EXECUTE** using Bash tool:
```bash
bash "${CLAUDE_SKILL_DIR}/scripts/check_deps.sh" install ENGINE_NAME 2>&1 && echo "---INSTALL_OK---" || echo "---INSTALL_FAILED---"
```
> **STOP if INSTALL_FAILED** -- report error and exit.
If user cancels -- STOP.
## Step 2: Engine Selection (first run only)
Check for saved config in order:
1. Project: `.claude/md-to-pdf.config.json`
2. Global: `~/.claude/md-to-pdf.config.json`
If `--engine` flag was provided -- use it (skip config lookup).
If no saved preference and no `--engine` flag -- use `AskUserQuestion` with the engine comparison table from Step 1. Save the choice:
```json
{
"engine": "reportlab",
"pygments_theme": "github"
}
```
Write to project config `.claude/md-to-pdf.config.json` (create `.claude/` dir if needed).
## Step 3: Mode Execution
### HELP Mode
Print formatted usage:
```
MD to PDF Converter
Usage:
/brewdoc:md-to-pdf <file.md> Convert with saved engine/style
/brewdoc:md-to-pdf <file.md> --engine weasyprint Convert with specific engine
/brewdoc:md-to-pdf <file.md> "remove section X" Preprocess MD then convert
/brewdoc:md-to-pdf styles Configure page/color/font
/brewdoc:md-to-pdf test Convert bundled test file
/brewdoc:md-to-pdf help Show this help
Engines:
reportlab -- Pure Python, fast, no system deps (pip install reportlab)
weasyprint -- HTML/CSS pipeline, best quality (pip + brew deps)
```
EXIT after printing.
### CONVERT Mode
1. Read the input MD file with Read tool. If not found -- STOP with error.
2. Determine output path: same directory, same name, `.pdf` extension.
3. Build the config path argument (if project or global config exists, add `--config CONFIG_PATH`).
**EXECUTE** using Bash tool:
```bash
python3 "${CLAUDE_SKILL_DIR}/scripts/md_to_pdf.py" "INPUT_PATH" "OUTPUT_PATH" --engine ENGINE --quiet 2>&1 && echo "---CONVERT_OK---" || echo "---CONVERT_FAILED---"
```
Replace `INPUT_PATH`, `OUTPUT_PATH`, `ENGINE` with actual values. Add `--config CONFIG_PATH` if a style config JSON exists. Add `--pygments-theme THEME` for weasyprint if configured.
> **STOP if CONVERT_FAILED** -- read error output, attempt fix, retry once. If still failing -- report error.
4. Parse structured output lines: `STATUS`, `OUTPUT`, `PAGES`, `SIZE`, `ENGINE`.
### CONVERT+PROMPT Mode
1. Read the input MD file with Read tool.
2. Apply LLM transformations per the `custom_prompt` instructions (delete sections, rewrite headings, restructure, etc.).
3. Write modified content to temp file: `{original_dir}/.tmp_{original_name}.md`
4. Run the converter on the temp file (same command as CONVERT mode, using temp file as input, original name for output).
5. Delete the temp file.
**EXECUTE** using Bash tool:
```bash
rm -f "TEMP_FILE_PATH"
```
6. Proceed to Step 4 with `preprocessing: true`.
### STYLES Mode
Run interactive configuration via `AskUserQuestion` dialogs:
**Question 1 -- Page size:**
Options: `A4` (default), `Letter`, `Legal`
**Question 2 -- Color scheme:**
Options: `Default blue` (primary #1a3a5c), `Dark` (primary #2d3748), `Custom` (ask for hex values)
**Question 3 -- Code theme (weasyprint only):**
Options: `github` (default), `monokai`, `friendly`, `solarized-dark`, `solarized-light`
**Question 4 -- Footer format:**
Options: `Page {page} of {total}` (default), `{page}/{total}`, `Disabled`
Build JSON config matching `styles/default.json` structure, overriding changed values. Write to `.claude/md-to-pdf.config.json`.
Report saved settings table and EXIT.
### TEST Mode
1. Use bundled test file at `${CLAUDE_SKILL_DIR}/test/test-all-elements.md` as INPUT_PATH.
2. Determine output path: `/tmp/md-to-pdf-test-ENGINE.pdf`
3. Run converter (same command as CONVERT mode, using test file as input, `/tmp/` output).
4. Proceed to Step 4.
## Step 4: Report Results
| Parameter | Value |
|-----------|-------|
| Source | absolute path to input MD |
| Output | absolute path to output PDF |
| Pages | from `PAGES=` in script output |
| Size | from `SIZE=` in script output |
| Engine | `reportlab` or `weasyprint` |
| Preprocessing | custom_prompt summary (if used) or `none` |
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.