1
0
Fork 0
Quick an easy Go program to convert md documents to print-ready HTML pages.
Find a file
2026-02-12 17:41:37 -06:00
src Initial commit 2026-02-12 17:41:37 -06:00
.gitignore Initial commit 2026-02-12 17:41:37 -06:00
example.md Initial commit 2026-02-12 17:41:37 -06:00
go.mod Initial commit 2026-02-12 17:41:37 -06:00
README.md Initial commit 2026-02-12 17:41:37 -06:00
volund.md Initial commit 2026-02-12 17:41:37 -06:00

Papergen

A lightweight command-line tool that converts Markdown files into print-ready HTML documents optimized for US Letter paper. Features embedded Merriweather fonts for professional typography.

Features

  • Zero Dependencies: Pure Go implementation using only standard library
  • Print-Optimized: Designed for clean printing on US Letter (8.5" × 11") paper
  • Flexible Fonts: Use system fonts (tiny files) or embed fonts (portable but large)
  • Custom Typography: Choose any font installed on your system
  • Professional Layout: Standard margins, proper page breaks, clean table designs
  • Directory Support: Combine multiple .md files into a single document

Supported Markdown

  • # Page Title - Document title (h1)
  • ## Section Heading - Section headers that start on new pages (h2)
  • Bold text with **bold**
  • Italic text with *italic* or _italic_
  • Unordered lists with - item or * item
  • Ordered lists with 1. item
  • Tables with standard markdown table syntax

Installation

Build from source:

go build -o papergen ./src

Usage

Basic Usage (Small Files with System Fonts)

By default, papergen uses system-installed fonts, creating small HTML files (~6KB):

./papergen -input document.md -output print.html

Note: The font must be installed on your system for proper rendering. Merriweather is the default but can be changed.

Custom Fonts

Use any font installed on your system:

./papergen -input document.md -font "Crimson Text" -fallback "Times, serif"
./papergen -input document.md -font "Georgia"

Embedded Fonts (Self-Contained, Large Files)

For truly portable documents that work offline on any system:

./papergen -input document.md -embed-fonts

Warning: Creates ~24MB HTML file due to embedded font data. Only use if portability is critical.

Directory Input

Combine all .md files in a directory (alphabetically sorted):

./papergen -input ./docs -output combined.html

Example

Create a markdown file:

# My Document

## Introduction

This is a paragraph with **bold** and *italic* text.

## Data

| Name | Value |
| ---- | ----- |
| Item 1 | 100 |
| Item 2 | 200 |

Convert to HTML:

./papergen -input example.md -output example.html

Open example.html in your browser and print (Ctrl/Cmd+P). Each ## section will start on a new page.

Font Options Explained

Pros:

  • Tiny file size (~6KB)
  • Fast to generate and load
  • Works great if font is installed

Cons:

  • Requires font installed on viewing system
  • May fall back to Georgia/serif if font unavailable

When to use: Most cases, especially for personal use or when you know the font is installed

Embedded Fonts

Pros:

  • Completely self-contained
  • Works on any system
  • Guaranteed consistent rendering

Cons:

  • Large file size (~24MB)
  • Slower to generate and load

When to use: Need guaranteed rendering on unknown systems, archival purposes, or distributing to users without fonts installed

Print Styling

  • Page Size: US Letter (8.5" × 11")
  • Margins: 1 inch top/bottom, 0.75 inch sides
  • Default Font: Merriweather serif at 11pt (customizable with -font flag)
  • Line Height: 1.6 for readability
  • Tables: Clean borders using line weight, no background colors
  • Page Breaks: Automatic at section headings (##)

Output Format

The generated HTML includes:

  • Complete CSS for print optimization
  • Optional embedded fonts (base64-encoded) via -embed-fonts flag
  • Clean, standards-compliant HTML5

File sizes:

  • Default (system fonts): ~5-10KB - requires font installed on system
  • Embedded fonts: ~24MB - works on any system, fully portable

Technical Details

  • Language: Go 1.25+
  • Dependencies: None (stdlib only)
  • Architecture: Custom markdown parser with regex-based inline formatting
  • Font Embedding: TTF files converted to base64 data URIs

License

This tool uses the Merriweather font family, which is licensed under the SIL Open Font License.