Skip to content
pdf-conversion logo

Markdown to PDF Converter Skill

pdf-conversion

Converts Markdown files to professional PDF documents using WeasyPrint. Use when user wants to convert markdown to PDF, export as PDF, or generate PDF from documents. Supports custom CSS styling, page headers/footers, and Autodesk brand themes.

SKILL.md

Full skill instructions

Markdown to PDF Converter Skill

Purpose

Convert Markdown files to professional PDF documents using WeasyPrint (HTML→PDF engine) with customizable CSS styling. Runs entirely in sandbox with no external dependencies beyond Python packages.


Architecture

Technology Stack

ComponentLibraryPurpose
MD ParsermarkdownConvert Markdown → HTML with extensions
PDF EngineweasyprintRender HTML+CSS → PDF
StylingCustom CSSProfessional typography and layout

Why This Stack?

  • Pure Python: No subprocess calls, no external tools (Pandoc, LaTeX) required
  • Sandbox-Safe: Works within Cursor sandbox restrictions
  • CSS Control: Full styling customization via CSS
  • Quality Output: Professional typography with proper page handling

Features

Markdown Support

FeatureStatusNotes
Headers (h1-h6)✅Proper hierarchy styling
Bold/​Italic✅Standard inline formatting
Lists (ordered/​unordered)✅Nested list support
Code blocks✅Syntax-highlighted with fenced_code
Tables✅GFM-style tables
Links✅Clickable in PDF
Images✅Embedded (local paths)
Blockquotes✅Styled callouts
Horizontal rules✅Section dividers
Task lists✅Checkbox rendering
Footnotes✅End-of-document notes
Table of Contents✅Auto-generated with [TOC]

PDF Features

  • Page sizes: A4, Letter, Legal, custom dimensions
  • Margins: Configurable (default: 2.5cm)
  • Headers/​Footers: Page numbers, document title, date
  • Page breaks: Before major sections (configurable)
  • Typography: Professional fonts, proper line-height

Workflow

Step 1: Understand Request

  • What Markdown file(s) need conversion?
  • Any specific styling requirements?
  • Output filename/​location preference?
  • Page size requirements (A4 default)?

Step 2: Check/​Setup Environment

# One-time setup (if not done)
cd /​Users/​samarvir/​code/​autodesk/​Product\ management
source .venv/​bin/​activate
pip install markdown weasyprint

Step 3: Execute Conversion

# Basic conversion
python .claude/​skills/​md-to-pdf/​convert_md_to_pdf.py input.md output.pdf

# With options
python .claude/​skills/​md-to-pdf/​convert_md_to_pdf.py input.md output.pdf \
  --css custom.css \
  --page-size letter \
  --title "Document Title"

Step 4: Report Results

**PDF Generated Successfully**

**Input**: input.md
**Output**: Output/​document.pdf
**Pages**: [N] pages
**Size**: [X] KB

Styling: [default/​custom CSS path]

Usage Options

Command Line Arguments

ArgumentTypeDefaultDescription
inputpositionalrequiredInput Markdown file path
outputpositionalrequiredOutput PDF file path
--cssstringdefault.cssCustom CSS file path
--page-sizestringa4Page size: a4, letter, legal
--marginstring2.5cmPage margins
--titlestring(from md)Document title for header
--no-tocflagfalseDisable table of contents
--no-headerflagfalseDisable page header
--no-footerflagfalseDisable page footer

Examples

Basic Conversion
python .claude/​skills/​md-to-pdf/​convert_md_to_pdf.py \
  Initiatives/​docs-integration/​prd.md \
  Output/​prd.pdf
With Custom Styling
python .claude/​skills/​md-to-pdf/​convert_md_to_pdf.py \
  Initiatives/​ai-renderings/​case-for-a-new-squad.md \
  Operations/​adhoc/​ai-renderings/​proposal.pdf \
  --css .claude/​skills/​md-to-pdf/​styles/​autodesk.css \
  --title "AI Renderings Squad Proposal"
Letter Size for US Audience
python .claude/​skills/​md-to-pdf/​convert_md_to_pdf.py \
  document.md \
  document.pdf \
  --page-size letter \
  --margin 1in

CSS Themes

Available Themes

ThemeFileUse Case
Defaultdefault.cssClean, professional documents
Autodeskautodesk.cssAutodesk brand colors
Minimalminimal.cssSimple, no-frills output

Custom CSS

Create your own CSS file with:

  • @page rules for margins, headers, footers
  • Typography settings (fonts, sizes, line-height)
  • Table styling
  • Code block formatting
  • Color schemes

Example custom CSS sections:

/​* Page setup */
@page {
  size: A4;
  margin: 2.5cm;
  @top-center { content: "Document Title"; }
  @bottom-right { content: "Page " counter(page); }
}

/​* Typography */
body {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.6;
}

/​* Headers */
h1 { color: #1D91D0; page-break-before: always; }
h1:first-of-type { page-break-before: avoid; }

Output Location Guidelines

Follow the project's Output Location Protocol:

Document TypeSave ToExample
Initiative PRDsInitiatives/[name]/Initiatives/​ai-renderings/​prd.pdf
Leadership DocsOperations/​recurring/leadership-reviews/​q1-2026.pdf
Ad-hoc AnalysisOperations/​adhoc/[topic]/adhoc/​market-analysis/​report.pdf
Test/​TemporaryOutput/Output/​test.pdf

Security Compliance

RuleImplementation
No user input in file pathsValidated input/​output paths
No eval/execPure library API calls
No subprocessWeasyPrint is pure Python
Input validationFile existence checks
Sandboxed executionRuns in Cursor sandbox
Resource limitsHandles large files gracefully

Input Sanitization

  • HTML content is escaped by default
  • Raw HTML in Markdown disabled unless explicitly enabled
  • Image paths validated (local only, no URLs without flag)
  • File size warnings for documents > 1MB source

Troubleshooting

Common Issues

IssueCauseFix
Missing fontsSystem fonts not availableUse web-safe fonts in CSS
Images not showingRelative paths brokenUse absolute paths or --base-path
Tables overflowWide tablesAdd table { width: 100%; } to CSS
No page breaksCSS missing rulesAdd h1 { page-break-before: always; }
WeasyPrint warningsFont/​CSS issuesUsually safe to ignore

Debug Mode

python .claude/​skills/​md-to-pdf/​convert_md_to_pdf.py input.md output.pdf --debug

Outputs:

  • Intermediate HTML (for inspection)
  • CSS applied
  • Any warnings/​errors

File Locations

FilePurpose
.claude/​skills/​md-to-pdf/​SKILL.mdThis documentation
.claude/​skills/​md-to-pdf/​convert_md_to_pdf.pyMain converter script
.claude/​skills/​md-to-pdf/​default.cssDefault styling
.claude/​skills/​md-to-pdf/​styles/Additional CSS themes

Setup (One-Time)

cd /​Users/​samarvir/​code/​autodesk/​Product\ management
source .venv/​bin/​activate
pip install markdown weasyprint

Dependencies

PackageVersionPurpose
markdown>=3.4Markdown parsing with extensions
weasyprint>=60.0HTML to PDF rendering

System Requirements

WeasyPrint requires some system libraries. On macOS:

brew install pango

If you encounter font issues:

brew install fontconfig

API Usage (Programmatic)

For integration with other scripts:

from convert_md_to_pdf import MarkdownToPDF

converter = MarkdownToPDF(
    css_path="default.css",
    page_size="a4",
    margin="2.5cm"
)

# Convert file
converter.convert_file("input.md", "output.pdf")

# Convert string
converter.convert_string(
    markdown_text="# Hello World\n\nThis is a test.",
    output_path="output.pdf",
    title="Test Document"
)

Best Practices

DO

  • ✅ Use semantic Markdown (proper header hierarchy)
  • ✅ Keep images local or use absolute URLs
  • ✅ Test with --debug first for complex documents
  • ✅ Use CSS for all styling (not inline HTML)
  • ✅ Add [TOC] for documents > 5 pages

DON'T

  • ❌ Embed raw HTML unless necessary
  • ❌ Use complex nested tables
  • ❌ Expect pixel-perfect browser rendering
  • ❌ Use remote images without --allow-remote flag

Response Templates

Conversion Acknowledgment

I'll convert the Markdown file to PDF.

**Input**: [filename.md]
**Output**: [path/​output.pdf]
**Styling**: [default/​custom]
**Page Size**: [A4/​Letter]

Converting...

Conversion Complete

**PDF Generated Successfully**

**File**: `Output/[filename].pdf`
**Pages**: [N] pages
**Size**: [X] KB

The PDF includes:
- [TOC if present]
- [N] sections
- [N] tables
- [N] images

Open the PDF to review formatting.

Conversion Failed

**PDF Generation Failed**

**Error**: [error message]

Troubleshooting:
1. [specific fix based on error]
2. Run with `--debug` for more info
3. Check CSS syntax if using custom styles

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View