md2pdf

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 12 Imported by: 0

README

md2pdf

A Go library and CLI tool for converting Markdown to PDF.

Uses goldmark for Markdown parsing and gopdf for PDF generation.

Features

  • Headings (h1-h6)
  • Bold, italic, and bold-italic text
  • Inline code and fenced code blocks with background shading
  • Ordered and unordered lists (nested)
  • Blockquotes
  • Horizontal rules
  • Automatic system font discovery (Noto Sans, DejaVu, Liberation)
  • Custom TTF font support
  • A4 page layout

Installation

go install github.com/alchemy/md2pdf/cmd/md2pdf@latest

CLI Usage

md2pdf input.md output.pdf

Custom fonts:

md2pdf input.md output.pdf --regular ./fonts/Regular.ttf --bold ./fonts/Bold.ttf --italic ./fonts/Italic.ttf --mono ./fonts/Mono.ttf

Library Usage

package main

import (
    "os"

    "github.com/alchemy/md2pdf"
)

func main() {
    conv := md2pdf.New(
        md2pdf.WithRegularFont("/path/to/regular.ttf"),
        md2pdf.WithBoldFont("/path/to/bold.ttf"),
    )

    in, _ := os.Open("input.md")
    defer in.Close()

    out, _ := os.Create("output.pdf")
    defer out.Close()

    conv.Convert(in, out)
}

If no fonts are specified, the converter automatically discovers system-installed TTF fonts.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter converts Markdown to PDF.

func New

func New(opts ...Option) *Converter

New creates a new Converter with the given options.

func (*Converter) Convert

func (c *Converter) Convert(src io.Reader, w io.Writer) error

Convert reads Markdown from src and writes PDF to w.

type Option

type Option func(*Converter)

Option configures the converter.

func WithBoldFont

func WithBoldFont(path string) Option

WithBoldFont sets the path for the bold TTF font.

func WithBoldItalicFont

func WithBoldItalicFont(path string) Option

WithBoldItalicFont sets the path for the bold-italic TTF font.

func WithItalicFont

func WithItalicFont(path string) Option

WithItalicFont sets the path for the italic TTF font.

func WithMonoFont

func WithMonoFont(path string) Option

WithMonoFont sets the path for the monospace TTF font.

func WithRegularFont

func WithRegularFont(path string) Option

WithRegularFont sets the path for the regular TTF font.

Directories

Path Synopsis
cmd
md2pdf command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL