
Pdf Generator
- 28 installs
- 84 repo stars
- Updated January 28, 2026
- aidotnet/moyucode
pdf-generator is a Claude Code skill that generates PDF documents from HTML, Markdown, or text with customizable styling and layout.
About
pdf-generator is a Claude Code skill that converts Markdown, HTML, or plain text into PDF documents. A developer runs its bundled Python script to export reports and docs with a custom title, author, and page size. It depends on the markdown and weasyprint libraries for rendering and layout.
- Generates PDF documents from Markdown, HTML, or plain text
- Supports custom title, author, page size, and styling
- Bundled Python script using markdown + weasyprint
Pdf Generator by the numbers
- 28 all-time installs (skills.sh)
- Ranked #415 of 688 Office & Documents skills by installs in the Skillselion catalog
- Data as of Jul 28, 2026 (Skillselion catalog sync)
pdf-generator capabilities & compatibility
- Capabilities
- pdf generation · markdown to pdf · html to pdf · document export
- Use cases
- documentation · pdf parsing
- Pricing
- Free
What pdf-generator says it does
Generate PDF documents from HTML, Markdown, or text with customizable styling and layout.
pip install markdown weasyprint
npx skills add https://github.com/aidotnet/moyucode --skill pdf-generatorAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 28 |
|---|---|
| repo stars | ★ 84 |
| Last updated | January 28, 2026 |
| Repository | aidotnet/moyucode ↗ |
What it does
Export Markdown, HTML, or text content into styled PDF documents from the command line.
Who is it for?
Exporting Markdown or HTML content to styled PDF files
Skip if: Parsing or extracting data out of existing PDFs
When should I use this skill?
You need to turn a Markdown, HTML, or text file into a PDF
What you get
A PDF file rendered from Markdown, HTML, or text input
- A generated PDF document
By the numbers
- Accepts 3 input formats: Markdown, HTML, and plain text
Files
PDF Generator Tool
Description
Generate PDF documents from HTML, Markdown, or text with customizable styling and layout.
Trigger
/generate-pdfcommand- User requests PDF generation
- User needs to export document as PDF
Usage
# Generate PDF from Markdown
python scripts/generate_pdf.py --input "document.md" --output "document.pdf"
# Generate PDF from HTML
python scripts/generate_pdf.py --input "report.html" --output "report.pdf" --format html
# Generate PDF with custom options
python scripts/generate_pdf.py --input "doc.md" --output "doc.pdf" --title "My Report" --author "John" --page-size A4Tags
pdf, document, export, markdown, html
Compatibility
- Codex: ✅
- Claude Code: ✅
#!/usr/bin/env python3
"""
PDF Generator Tool
Generate PDF documents from Markdown, HTML, or plain text.
Usage:
python generate_pdf.py --input "document.md" --output "document.pdf"
python generate_pdf.py --input "report.html" --output "report.pdf" --format html
python generate_pdf.py --input "text.txt" --output "text.pdf" --title "My Document"
Requirements:
pip install markdown weasyprint
"""
import argparse
import sys
from pathlib import Path
try:
import markdown
from weasyprint import HTML, CSS
WEASYPRINT_AVAILABLE = True
except ImportError:
WEASYPRINT_AVAILABLE = False
try:
from reportlab.lib.pagesizes import letter, A4, legal
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
from reportlab.lib.enums import TA_JUSTIFY
REPORTLAB_AVAILABLE = True
except ImportError:
REPORTLAB_AVAILABLE = False
# Default CSS for PDF styling
DEFAULT_CSS = """
@page {
size: A4;
margin: 2cm;
}
body {
font-family: 'Helvetica', 'Arial', sans-serif;
font-size: 12pt;
line-height: 1.6;
color: #333;
}
h1 { font-size: 24pt; color: #1a1a1a; margin-top: 0; }
h2 { font-size: 18pt; color: #2a2a2a; }
h3 { font-size: 14pt; color: #3a3a3a; }
code {
background: #f4f4f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
pre {
background: #f4f4f4;
padding: 12px;
border-radius: 5px;
overflow-x: auto;
}
table {
border-collapse: collapse;
width: 100%;
margin: 1em 0;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th { background: #f4f4f4; }
blockquote {
border-left: 4px solid #ddd;
margin: 1em 0;
padding-left: 1em;
color: #666;
}
"""
def markdown_to_html(md_content: str, title: str = None) -> str:
"""Convert Markdown to HTML with styling."""
md = markdown.Markdown(extensions=[
'tables',
'fenced_code',
'codehilite',
'toc',
'meta',
])
html_body = md.convert(md_content)
title_tag = f"<title>{title}</title>" if title else ""
return f"""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
{title_tag}
<style>{DEFAULT_CSS}</style>
</head>
<body>
{f'<h1>{title}</h1>' if title else ''}
{html_body}
</body>
</html>
"""
def generate_pdf_weasyprint(html_content: str, output_path: str, css: str = None):
"""Generate PDF using WeasyPrint (better quality)."""
stylesheets = [CSS(string=DEFAULT_CSS)]
if css:
stylesheets.append(CSS(string=css))
HTML(string=html_content).write_pdf(output_path, stylesheets=stylesheets)
def generate_pdf_reportlab(text_content: str, output_path: str, title: str = None, page_size: str = "A4"):
"""Generate PDF using ReportLab (fallback, no external deps)."""
sizes = {"A4": A4, "letter": letter, "legal": legal}
size = sizes.get(page_size, A4)
doc = SimpleDocTemplate(
output_path,
pagesize=size,
rightMargin=72,
leftMargin=72,
topMargin=72,
bottomMargin=72
)
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(
name='Body',
parent=styles['Normal'],
fontSize=12,
leading=18,
alignment=TA_JUSTIFY,
))
story = []
if title:
story.append(Paragraph(title, styles['Title']))
story.append(Spacer(1, 0.5 * inch))
# Split content into paragraphs
paragraphs = text_content.split('\n\n')
for para in paragraphs:
if para.strip():
# Handle headers
if para.startswith('# '):
story.append(Paragraph(para[2:], styles['Heading1']))
elif para.startswith('## '):
story.append(Paragraph(para[3:], styles['Heading2']))
elif para.startswith('### '):
story.append(Paragraph(para[4:], styles['Heading3']))
else:
story.append(Paragraph(para.replace('\n', '<br/>'), styles['Body']))
story.append(Spacer(1, 0.2 * inch))
doc.build(story)
def generate_pdf(
input_path: str,
output_path: str,
format: str = "auto",
title: str = None,
author: str = None,
page_size: str = "A4",
css: str = None,
) -> bool:
"""
Generate PDF from input file.
Args:
input_path: Path to input file (md, html, txt)
output_path: Path for output PDF
format: Input format (auto, markdown, html, text)
title: Document title
author: Document author
page_size: Page size (A4, letter, legal)
css: Additional CSS styling
Returns:
True if successful, False otherwise
"""
input_file = Path(input_path)
if not input_file.exists():
print(f"Error: Input file not found: {input_path}", file=sys.stderr)
return False
# Read input content
content = input_file.read_text(encoding="utf-8")
# Auto-detect format
if format == "auto":
suffix = input_file.suffix.lower()
if suffix in [".md", ".markdown"]:
format = "markdown"
elif suffix in [".html", ".htm"]:
format = "html"
else:
format = "text"
try:
if WEASYPRINT_AVAILABLE:
# Use WeasyPrint for better quality
if format == "markdown":
html_content = markdown_to_html(content, title)
elif format == "html":
html_content = content
else:
# Wrap text in HTML
html_content = markdown_to_html(f"```\n{content}\n```", title)
generate_pdf_weasyprint(html_content, output_path, css)
elif REPORTLAB_AVAILABLE:
# Fallback to ReportLab
print("Note: Using ReportLab (install weasyprint for better quality)", file=sys.stderr)
generate_pdf_reportlab(content, output_path, title, page_size)
else:
print("Error: No PDF library available. Install: pip install weasyprint", file=sys.stderr)
return False
print(f"✓ PDF generated: {output_path}")
return True
except Exception as e:
print(f"Error generating PDF: {e}", file=sys.stderr)
return False
def main():
parser = argparse.ArgumentParser(
description="Generate PDF from Markdown, HTML, or text files",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
%(prog)s --input document.md --output document.pdf
%(prog)s --input report.html --output report.pdf --format html
%(prog)s --input notes.txt --output notes.pdf --title "My Notes"
"""
)
parser.add_argument("--input", "-i", required=True, help="Input file path")
parser.add_argument("--output", "-o", required=True, help="Output PDF path")
parser.add_argument("--format", "-f", choices=["auto", "markdown", "html", "text"],
default="auto", help="Input format (default: auto-detect)")
parser.add_argument("--title", "-t", help="Document title")
parser.add_argument("--author", "-a", help="Document author")
parser.add_argument("--page-size", choices=["A4", "letter", "legal"],
default="A4", help="Page size (default: A4)")
parser.add_argument("--css", help="Additional CSS file for styling")
args = parser.parse_args()
# Load custom CSS if provided
css = None
if args.css and Path(args.css).exists():
css = Path(args.css).read_text()
success = generate_pdf(
input_path=args.input,
output_path=args.output,
format=args.format,
title=args.title,
author=args.author,
page_size=args.page_size,
css=css,
)
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()
Related skills
FAQ
What inputs can it convert to PDF?
Markdown, HTML, or plain text files.
What does it need installed?
The script requires the markdown and weasyprint Python packages.