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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.