mdpdf

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 26 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mdpdf typesets Markdown as a PDF in pure Go, for the export_pdf tool (spec_006_filetools): GitHub-flavoured Markdown parsed by goldmark, laid out with fpdf in embedded Noto fonts, with an outline of the headings, page numbers, tables, highlighted code and the images the caller lets it read. Raw HTML is skipped and Mermaid diagrams print as their code: drawing them needs a browser, which the desktop app's own export has.

Index

Constants

View Source
const (
	A4     = "A4"
	Letter = "Letter"
)

Page sizes.

Variables

View Source
var ErrNotMarkdown = errors.New("not a text file")

ErrNotMarkdown is returned for input that isn't text.

Functions

func CheckText

func CheckText(data []byte) error

CheckText reports whether data looks like text (valid UTF-8, no NULs).

func PageSizeFor

func PageSizeFor(setting string) string

PageSizeFor resolves a [pdf] page_size setting: "a4", "letter", or "auto" (or empty), which picks Letter where the locale's country uses it.

Types

type Options

type Options struct {
	// PageSize is A4 or Letter (default A4).
	PageSize string
	// Title is the document's title in its properties; default the first
	// heading.
	Title string
	// ReadImage returns the bytes of an image the Markdown refers to, by
	// its destination as written (relative to the Markdown file). nil
	// prints images as their alt text, as it does for any it can't read.
	ReadImage func(dest string) ([]byte, error)
	// Time is the document's creation date (default now).
	Time time.Time
}

Options shape a document.

type Result

type Result struct {
	PDF   []byte
	Pages int
}

Result is a typeset document.

func Render

func Render(src []byte, o Options) (*Result, error)

Render typesets Markdown.

Jump to

Keyboard shortcuts

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