pdf

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 27 Imported by: 0 modules, 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 pdf renders Markdown to PDF for the GUI "PDF" toolbar button and the headless `--pdf` command-line flag.

It auto-selects the best available engine:

  • Chrome/Chromium/Edge (via the DevTools "print to PDF" command) when an installed browser is found. This produces high-fidelity output with selectable, vector text and full feature support (Mermaid diagrams, KaTeX math, syntax highlighting).
  • goldmark-pdf (pure Go) as a fallback that needs no browser and works completely offline - suitable for headless servers and containers.

All detection is pure Go with no webview linkage, so importing this package never adds a native dependency and is safe in headless environments.

Index

Constants

View Source
const (
	EngineChromium = "chromium"
	EngineGoldmark = "goldmark"
)

Engine names returned by GenerateAuto.

Variables

This section is empty.

Functions

func BrowserAvailable

func BrowserAvailable() bool

BrowserAvailable reports whether an installed Chrome/Chromium/Edge browser was found that could be used for high-fidelity PDF export.

func FindBrowser

func FindBrowser() (string, bool)

FindBrowser locates an installed Chrome/Chromium/Edge executable that can be driven headlessly to print a page to PDF. It returns the executable path and true when one is found.

The MDV_CHROME (and the de-facto standard CHROME_BIN) environment variable overrides detection, letting users point mdv at a specific browser binary.

func NativeAvailable

func NativeAvailable() bool

NativeAvailable reports whether the high-fidelity headless-browser engine can be used: it needs both an installed browser and the embedded print bundle (present only in release builds compiled with `-tags pdf_bundled`). The GUI uses it to decide between Chrome's printToPDF and the in-webview html2pdf.js fallback.

func RenderChromium

func RenderChromium(markdown []byte, srcDir string, extended, allowRemote bool, w io.Writer) error

RenderChromium renders markdown to w using the headless-browser engine only (no goldmark fallback), so the caller can choose its own fallback. It returns an error when either a browser or the embedded print bundle is unavailable.

srcDir resolves relative images and may be empty; extended enables the opt-in inline Markdown syntax; allowRemote permits fetching remote (http/https) images and assets (blocked by default).

Types

type Result

type Result struct {
	Engine   string
	Warnings []string
}

Result describes the outcome of a PDF generation: which engine was used and any non-fatal warnings about content that was filtered or dropped (for example HTML tags or unsupported images in the pure-Go goldmark engine).

func GenerateAuto

func GenerateAuto(markdown []byte, srcDir string, allowRemote bool, w io.Writer) (Result, error)

GenerateAuto renders markdown to w, choosing the best available engine. When a browser and the embedded print bundle are both available it uses headless Chrome (full fidelity: Mermaid, KaTeX, syntax highlighting, selectable text); otherwise it falls back to the pure-Go goldmark-pdf engine, which needs no browser and works offline. The Result reports the engine used and any warnings about content the engine had to filter out.

srcDir is the directory the document lives in, used to resolve relative image references; it may be empty for stdin input. allowRemote permits fetching remote (http/https) images and assets; when false (the default) nothing is loaded from the network.

Jump to

Keyboard shortcuts

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