
A professional macOS utility that applies letterhead templates to PDF and Markdown documents. Mac-letterhead creates drag-and-drop applications that automatically merge your company letterhead with documents while preserving formatting and ensuring professional presentation.
Mac-letterhead transforms your letterhead PDF into a powerful document processing tool:
- Direct Overlay: Your letterhead is applied as an overlay to existing PDFs without reformatting the original document
- Multiple Blend Modes: Choose from various merging strategies (darken, multiply, overlay, transparency) to suit different letterhead designs
- Quality Preservation: All original formatting, fonts, and layout are maintained during the merge process
- Intelligent Layout: Analyzes your letterhead PDF to identify headers, footers, logos, and text elements
- Smart Margin Detection: Automatically calculates the optimal printable area within your letterhead design
- Professional Rendering: Converts Markdown to beautifully formatted PDF with proper typography, tables, code blocks, and styling
- Adaptive Positioning: Handles left, right, and center-positioned letterheads with appropriate margin adjustments
- Single Page: Applied consistently to all document pages
- Two Pages: First page template for page 1, second template for subsequent pages
- Three Pages: Distinct templates for first page, even pages, and odd pages
- macOS: Required for droplet applications and PDF processing
- Python: 3.10 or higher
- uv package manager: Install with
pip install uv
if needed
Install Mac-letterhead and create your first letterhead application:
# Quick start - create a letterhead droplet on your desktop
uvx mac-letterhead install --name "Company"
# For AI integration, install with MCP support
uvx install "mac-letterhead[mcp]"
Mac-letterhead expects your letterhead files to be organized in ~/.letterhead/
:
~/.letterhead/
├── company.pdf # Your letterhead template
├── company.css # Optional custom styling
└── personal.pdf # Additional letterhead templates
This creates a macOS application that you can drag documents onto to apply your letterhead. The MCP option adds support for AI tool integration.
For optimal Markdown rendering, install the required libraries:
brew install pango cairo fontconfig freetype harfbuzz
These libraries enable high-quality PDF generation with advanced typography support.
# Create a letterhead droplet using ~/.letterhead/company.pdf
uvx mac-letterhead install --name "company"
# Use a different letterhead file but keep the app name
uvx mac-letterhead install --name "Company Correspondence" --letterhead /path/to/custom-letterhead.pdf
# Create a letterhead application with custom CSS styling
uvx mac-letterhead install --name "Technical Reports" --css /path/to/custom-styles.css
The --css
option allows you to customize the appearance of rendered Markdown documents:
- Typography: Custom fonts, sizes, colors, and spacing
- Layout: Table styling, code block formatting, list appearance
- Branding: Consistent styling that complements your letterhead design
- Responsiveness: Ensures content fits properly within the detected printable area
The install command follows this pattern:
uvx mac-letterhead install --name "AppName" [--letterhead path] [--css path] [--output-dir dir]
Required:
--name
: Sets both the application name and the style. Automatically looks for~/.letterhead/<name>.pdf
and~/.letterhead/<name>.css
Optional:
--letterhead
: Override the default letterhead PDF path--css
: Override the default CSS file path--output-dir
: Specify where to create the app (default: Desktop)--dev
: Create a development version using local code
Once created, your letterhead application appears on your desktop:
- For PDF Files: Drag any PDF onto the application icon - the letterhead is applied as an overlay
- For Markdown Files: Drag .md files onto the application - they're converted to PDF with your letterhead and proper formatting
- Preview Letterhead: Double-click the application to view information and preview the letterhead template
# Apply letterhead to a PDF document
uvx mac-letterhead merge /path/to/letterhead.pdf "Document Title" ~/Desktop /path/to/document.pdf
# Use a specific blending strategy
uvx mac-letterhead merge /path/to/letterhead.pdf "Report" ~/Desktop /path/to/report.pdf --strategy overlay
# Convert Markdown with letterhead
uvx mac-letterhead merge-md /path/to/letterhead.pdf "Technical Guide" ~/Desktop /path/to/guide.md
# With custom CSS styling
uvx mac-letterhead merge-md /path/to/letterhead.pdf "Proposal" ~/Desktop /path/to/proposal.md --css /path/to/styles.css
Mac-letterhead includes an MCP (Model Context Protocol) server that enables AI tools like Claude to create letterheaded PDFs through natural language commands:
# Start a generic multi-style server
uvx mac-letterhead mcp
# Start a dedicated single-style server
uvx mac-letterhead mcp --style easytocloud --output-dir ~/Documents/generated-pdfs
Usage Examples with Claude:
- "Using the letterhead server, create an easytocloud style PDF about our new cloud services"
- "Generate a personal letterheaded document for my consulting proposal"
The MCP server automatically:
- Converts Markdown content to professionally formatted PDFs
- Applies appropriate letterhead templates and CSS styling
- Manages output directories and file naming
- Supports both style-specific and generic multi-style configurations
For complete MCP setup and configuration details, see README_MCP.md.
Choose the optimal strategy for your letterhead design:
darken
(Default): Ideal for light letterheads with dark text/logos - provides excellent readabilitymultiply
: Creates watermark-like effects, good for subtle brandingoverlay
: Balances visibility of both document content and letterhead elementstransparency
: Smooth blending with semi-transparent effectsreverse
: Places letterhead elements on top of document content
Create sophisticated document styling by providing custom CSS:
/* custom-styles.css */
h1 { color: #2c5aa0; border-bottom: 2px solid #2c5aa0; }
table { border: 1px solid #ddd; background: #f9f9f9; }
code { background: #f4f4f4; padding: 2px 4px; }
The CSS is automatically integrated with Mac-letterhead's smart margin system to ensure content fits properly within your letterhead design.
Mac-letterhead provides professional Markdown rendering with:
- Typography: Proper heading hierarchy, paragraph spacing, and font sizing
- Tables: Clean borders, consistent padding, and professional appearance
- Code Blocks: Syntax highlighting for multiple programming languages
- Lists & Quotes: Proper indentation and formatting for nested content
- Images & Links: Full support for embedded images and hyperlinks
- Math: LaTeX-style mathematical expressions (when supported)
Mac-letterhead includes enhanced support for GitHub Flavored Markdown (GFM) features:
- Strikethrough:
~~deleted text~~
renders with proper strikethrough formatting - Task Lists: Interactive-style checkboxes with
- [x] completed
and- [ ] pending
- Enhanced Tables: Improved table rendering with better alignment and styling
- Automatic Detection: GFM features are automatically enabled when the pycmarkgfm library is available
Task lists are rendered with professional Unicode checkboxes (☑ for completed, ☐ for pending) that are properly sized and aligned, including within table cells.
Mac-letterhead features a sophisticated dual-backend rendering system that automatically selects the best available technology while providing manual control when needed.
WeasyPrint (Preferred when available):
- Advantages: Superior CSS support, advanced typography, precise layout control
- Features: Full HTML5/CSS3 support, web fonts, complex layouts, print-specific CSS
- Requirements: System libraries (
brew install pango cairo fontconfig freetype harfbuzz
) - Use Case: High-quality documents requiring advanced styling and typography
ReportLab (Reliable fallback):
- Advantages: Pure Python implementation, no system dependencies, consistent rendering
- Features: Professional PDF generation, basic HTML support, reliable cross-platform operation
- Requirements: None (included with Python installation)
- Use Case: Simple documents, environments without system library access
GitHub Flavored Markdown (GFM) (Enhanced when available):
- Library: pycmarkgfm (Python bindings to GitHub's cmark-gfm parser)
- Features: Strikethrough, task lists, enhanced tables, autolinks, GitHub-compatible parsing
- Compatibility: Full compatibility with GitHub markdown rendering
- Use Case: Documents with GFM-specific features, GitHub repository documentation
Standard Markdown (Universal fallback):
- Library: Python markdown with extensions
- Features: CommonMark compliance, basic table support, code highlighting
- Compatibility: Works in all Python environments
- Use Case: Simple documents, maximum compatibility requirements
Automatic Selection (Default behavior):
# Uses best available backends automatically
uvx mac-letterhead merge-md letterhead.pdf "Document" ~/Desktop document.md
Manual Backend Control:
# Force specific PDF backend
uvx mac-letterhead merge-md letterhead.pdf "Report" ~/Desktop report.md --pdf-backend reportlab
# Force specific Markdown backend
uvx mac-letterhead merge-md letterhead.pdf "Guide" ~/Desktop guide.md --markdown-backend standard
# Combine specific backends
uvx mac-letterhead merge-md letterhead.pdf "Technical" ~/Desktop tech.md --pdf-backend weasyprint --markdown-backend gfm
Available Backend Options:
--pdf-backend
:weasyprint
,reportlab
,auto
(default:auto
)--markdown-backend
:gfm
,standard
,auto
(default:auto
)
Feature | WeasyPrint + GFM | WeasyPrint + Standard | ReportLab + GFM | ReportLab + Standard |
---|---|---|---|---|
Basic Markdown | ✅ Excellent | ✅ Excellent | ✅ Good | ✅ Good |
Advanced CSS | ✅ Full Support | ✅ Full Support | ||
Strikethrough | ✅ Native | ❌ Not Available | ✅ Unicode | ❌ Not Available |
Task Lists | ✅ Styled Checkboxes | ❌ Not Available | ✅ Unicode Checkboxes | ❌ Not Available |
Complex Tables | ✅ Advanced | ✅ Good | ✅ Basic | ✅ Basic |
Typography | ✅ Professional | ✅ Professional | ✅ Standard | ✅ Standard |
System Dependencies | ✅ None | ✅ None |
The project includes comprehensive testing for all backend combinations:
# Test all combinations across Python versions
make test-backend-combinations
# Test specific combinations
make test-weasyprint-gfm # WeasyPrint + GitHub Flavored Markdown
make test-weasyprint-standard # WeasyPrint + Standard Markdown
make test-reportlab-gfm # ReportLab + GitHub Flavored Markdown
make test-reportlab-standard # ReportLab + Standard Markdown
Each test combination generates output files with naming patterns like document-py3.11-weasyprint-gfm.pdf
for easy comparison and quality validation.
- Corporate Communications: Apply company branding to business correspondence
- Legal Documents: Add firm letterhead and disclaimers to contracts and legal papers
- Financial Documents: Brand invoices, statements, and financial reports
- Technical Documentation: Convert Markdown documentation to branded PDFs
- Academic Papers: Add institutional letterhead to research papers and reports
- Proposals & Reports: Create professional client deliverables from Markdown sources
- AI-Generated Content: Use Claude or other AI tools to create branded documents through natural language
Library Dependencies: If you see WeasyPrint warnings, the system automatically falls back to ReportLab - functionality is not affected.
File Permissions: If applications request file access, approve the permissions in System Preferences > Security & Privacy > Privacy > Files and Folders.
Margin Detection: The system automatically analyzes letterhead positioning. If margins appear incorrect, ensure your letterhead PDF contains clear visual elements (logos, text, graphics) in header/footer areas.
- Application logs:
~/Library/Logs/Mac-letterhead/letterhead.log
- Droplet logs:
~/Library/Logs/Mac-letterhead/droplet.log
We welcome contributions! Please see CONTRIBUTING.md for development setup, testing procedures, and pull request guidelines.
MIT License