Skip to main content

PDF Generation Skill

PDF Generation Skill

When to Use This Skill

Use this skill when implementing pdf generation patterns in your codebase.

How to Use This Skill

  1. Review the patterns and examples below
  2. Apply the relevant patterns to your implementation
  3. Follow the best practices outlined in this skill

The PDF Generation skill provides publication-grade document conversion capabilities for the CODITECT framework. It transforms Markdown documentation into professionally formatted PDFs with consistent branding, Mermaid diagram rendering, and enterprise-quality output.


Skill Definition

name: pdf-generation
description: Generate publication-grade PDFs from Markdown with Mermaid diagrams, CODITECT branding, and professional formatting
category: documentation
version: 1.0.0
author: Hal Casteel, Founder/CEO/CTO
copyright: 2025 AZ1.AI Inc.

capabilities:
- markdown_to_pdf
- mermaid_rendering
- cover_page_generation
- toc_generation
- batch_processing
- consistent_branding

dependencies:
python:
- md2pdf-mermaid
- markdown
- pyyaml
npm:
- "@mermaid-js/mermaid-cli"
- md-to-pdf

triggers:
- pattern: "generate.*pdf"
- pattern: "publish.*document"
- pattern: "convert.*markdown.*pdf"
- pattern: "create.*publication"

Usage Patterns

Pattern 1: Single Document Conversion

# Using the script directly
python3 scripts/generate-publication-pdf.py docs/architecture.md

# With options
python3 scripts/generate-publication-pdf.py docs/README.md --cover --toc --title "User Guide"

Pattern 2: Batch Processing

# Convert all markdown in a directory
python3 scripts/generate-publication-pdf.py --batch docs/00-coditect-introduction/

# With custom output directory
python3 scripts/generate-publication-pdf.py --batch docs/architecture/ --output /tmp/pdfs/

Pattern 3: Via Slash Command

# In Claude Code session
/publish-pdf docs/WHAT-IS-CODITECT-CORE.md

# Batch mode
/publish-pdf --batch docs/00-coditect-introduction/

Pattern 4: Via Agent

Task(
subagent_type="pdf-publishing-specialist",
prompt="Generate publication PDF for the architecture documentation"
)

Templates & Configuration

Directory Structure

docs/99-publishing/
├── templates/
│ ├── header.html # Page header template
│ ├── footer.html # Page footer with page numbers
│ ├── cover-page.html # Cover page template
│ └── coditect-theme.css # CODITECT brand styling
└── config/
└── pdf-generation-config.json # Default settings

CSS Theme Features

The CODITECT theme (coditect-theme.css) provides:

  • Typography: Inter font family, optimized line heights
  • Colors: CODITECT brand palette (#2563eb primary)
  • Code Blocks: Syntax highlighting with dark theme
  • Tables: Striped rows, branded headers
  • Callouts: Info, warning, error, success styles
  • Print Optimization: Page break controls, color accuracy

Configuration Options

{
"defaults": {
"page_size": "A4",
"include_cover": true,
"include_toc": true,
"page_numbers": true
},
"branding": {
"organization": "AZ1.AI Inc.",
"author": "Hal Casteel, Founder/CEO/CTO",
"copyright_year": 2025
},
"mermaid": {
"enabled": true,
"theme": "default",
"output_format": "png",
"scale": 2
}
}

Output Specifications

Page Layout

PropertyValue
Page SizeA4 (210mm × 297mm)
Top Margin25mm
Bottom Margin25mm
Left Margin20mm
Right Margin20mm

Branding Elements

ElementContent
HeaderCODITECT logo + Document title
FooterCopyright © 2025 AZ1.AI Inc. | Author | Page X of Y
CoverLogo, title, author, date, version, classification

Quality Metrics

MetricTarget
Image Resolution2x scale (retina)
Font EmbeddingFull
PDF Version1.7
CompressionEnabled

Mermaid Diagram Support

Supported Diagram Types

  • Flowcharts (graph TD, graph LR)
  • Sequence Diagrams (sequenceDiagram)
  • Class Diagrams (classDiagram)
  • State Diagrams (stateDiagram-v2)
  • Entity Relationship (erDiagram)
  • Gantt Charts (gantt)
  • Pie Charts (pie)
  • Git Graphs (gitGraph)

Rendering Pipeline

  1. Extract Mermaid code blocks from Markdown
  2. Write each diagram to temporary .mmd file
  3. Render via mermaid-cli to PNG (2x scale)
  4. Replace code block with image reference
  5. Include rendered image in final PDF

Example

Source Markdown:

```mermaid
graph TD
A[Start] --> B[Process]
B --> C[End]
```

Rendered Output:

  • PNG image at 2x resolution
  • Embedded in PDF at original size
  • White background for print compatibility

Error Handling

Dependency Checks

# Verify all dependencies
python3 scripts/generate-publication-pdf.py --check-deps

Common Errors

ErrorSolution
ModuleNotFoundError: md2pdf_mermaidpip install md2pdf-mermaid
mmdc: command not foundnpm install -g @mermaid-js/mermaid-cli
Parse error in mermaid diagramValidate at mermaid.live
PDF output emptyCheck input file path and permissions

Fallback Chain

The skill attempts PDF generation in this order:

  1. md2pdf-mermaid (Python, preferred)
  2. md-to-pdf (npm/npx)
  3. Pandoc + wkhtmltopdf (fallback)

Integration Points

ComponentTypeDescription
pdf-publishing-specialistAgentAutonomous PDF publishing agent
/publish-pdfCommandSlash command for PDF generation
generate-publication-pdf.pyScriptCore generation script
docs/99-publishing/TemplatesBranding and configuration

Workflow Integration

# In multi-step workflow
steps = [
"Edit documentation",
"Run /publish-pdf to generate PDFs",
"Review generated PDFs",
"Commit and distribute"
]

Best Practices

Content Preparation

  1. Use clear heading hierarchy (H1 → H2 → H3)
  2. Validate Mermaid syntax before generation
  3. Include frontmatter with title and metadata
  4. Keep tables simple for better rendering
  5. Use relative paths for images

Performance

  1. Batch similar documents together
  2. Pre-render complex diagrams if reusing
  3. Cache generated PDFs for unchanged content
  4. Use --no-cover for quick drafts

Quality Assurance

  1. Check all diagrams rendered correctly
  2. Verify page breaks are appropriate
  3. Review table formatting in output
  4. Validate hyperlinks work in PDF
  5. Test print output matches screen

Version History

VersionDateChanges
1.0.02025-12-16Initial skill definition

Success Output

When successful, this skill MUST output:

✅ SKILL COMPLETE: pdf-generation

Completed:
- [x] PDF generated with publication-grade quality
- [x] Mermaid diagrams rendered correctly
- [x] CODITECT branding applied (cover, header, footer)
- [x] Table of contents generated
- [x] All images embedded correctly

Outputs:
- path/to/document.pdf (publication-ready)
- path/to/document-cover.html (if --cover used)
- /tmp/mermaid-diagrams/*.png (rendered diagrams)
- PDF metadata (author, title, copyright)

Completion Checklist

Before marking this skill as complete, verify:

  • PDF file generated successfully
  • All Mermaid diagrams rendered as images
  • Cover page includes correct title and metadata
  • Table of contents links work correctly
  • Page numbers appear in footer
  • CODITECT branding applied to header/footer
  • All images display correctly in PDF
  • Print preview shows proper formatting
  • PDF file size is reasonable (<10MB for typical docs)
  • Hyperlinks work in PDF viewer

Failure Indicators

This skill has FAILED if:

  • ❌ PDF file not created or empty
  • ❌ Mermaid diagrams missing or showing as code blocks
  • ❌ Cover page template not found or incorrect
  • ❌ Table of contents broken or missing
  • ❌ Page breaks in wrong locations
  • ❌ Images missing or broken in PDF
  • ❌ CODITECT branding incomplete (missing logo/copyright)
  • ❌ Syntax errors in Mermaid diagrams
  • ❌ Dependencies missing (md2pdf-mermaid, mmdc)
  • ❌ PDF file size exceeds 50MB

When NOT to Use

Do NOT use this skill when:

  • Need HTML output only (use markdown rendering instead)
  • Converting simple text files (use basic PDF converters)
  • Need editable output (use DOCX conversion)
  • Creating forms or fillable PDFs (use form-specific tools)
  • Generating reports with dynamic data (use report-generation skill)
  • Need LaTeX-quality academic papers (use LaTeX workflow)
  • Creating slideshows/presentations (use presentation tools)

Use alternative skills:

  • markdown-to-html - Web-friendly HTML output
  • report-generation - Dynamic data-driven reports
  • latex-workflow - Academic paper formatting
  • documentation-publishing - Multi-format documentation sites

Anti-Patterns (Avoid)

Anti-PatternProblemSolution
No dependency checkPDF generation fails silentlyRun --check-deps before batch processing
Complex Mermaid diagramsRendering failures or unreadable outputTest at mermaid.live, simplify if needed
Missing frontmatterNo metadata in cover pageAdd YAML frontmatter to source markdown
Large embedded imagesHuge PDF file sizesOptimize images before conversion
Relative image pathsBroken images in PDFUse absolute paths or place images in same dir
No print testingOutput doesn't match expectationsAlways review print preview before distribution
Batch without verificationSilent failures unnoticedCheck each PDF after batch processing
Missing CSS themeInconsistent brandingAlways use CODITECT theme or custom CSS

Principles

This skill embodies these CODITECT principles:

  • #2 First Principles - Understanding PDF rendering pipeline (Markdown → HTML → PDF)
  • #3 Keep It Simple - Single command generates publication-ready output
  • #4 Self-Provisioning - Auto-install dependencies, create templates
  • #6 Clear, Understandable, Explainable - Professional formatting communicates authority
  • #7 Inform, Don't Ask - Automatic fallback chain for PDF generation
  • #10 Complete Execution - Full pipeline from source to branded PDF

Full Principles: CODITECT-STANDARD-AUTOMATION.md


Owner: AZ1.AI Inc. Lead: Hal Casteel, Founder/CEO/CTO Framework Version: CODITECT v1.7.2 Last Updated: December 16, 2025