Documentation
¶
Overview ¶
Package prettypdf transforms MDX source files into print-ready PDFs via headless Chrome.
It is both a composable Go library and a CLI tool. The library exposes a pipeline with step-by-step methods (ParseDir, ValidateDoc, ComposeHTML, Render) and 18 functional options for full customization.
Quick start (library) ¶
pdf, err := prettypdf.New(
prettypdf.WithSourceDir("./docs"),
prettypdf.WithOutputFile("output.pdf"),
prettypdf.WithTitle("My Book"),
)
if err != nil {
log.Fatal(err)
}
if err := pdf.Build(context.Background()); err != nil {
log.Fatal(err)
}
Quick start (CLI) ¶
go install github.com/sazardev/go-pretty-pdf/cmd/pretty-pdf@latest pretty-pdf build --source ./docs --out out.pdf
MDX files require frontmatter with an `id` field in [X.Y.Z] format (e.g. `[1.0.0]`). Documents are sorted by ID, not filename. Variables in {{key}} syntax are substituted before parsing.
Built-in custom components: <DeepDive>, <Warning>, <Axiom>. Additional components can be registered via WithComponent().
Index ¶
- func ComposeHTML(docs []*mdx.Document, opts ComposeOptions) (string, error)
- type ComposeOptions
- type Option
- func WithAuthor(author string) Option
- func WithCSS(css string) Option
- func WithComponent(name string, handler mdx.ComponentHandler) Option
- func WithConfig(cfg *config.Config) Option
- func WithConfigCSSAndTemplate(cfg *config.Config) Option
- func WithHeaderTitle(title string) Option
- func WithOutputFile(path string) Option
- func WithPaperSize(width, height float64) Option
- func WithRenderMargins(top, bottom, left, right float64) Option
- func WithSourceDir(dir string) Option
- func WithSubtitle(subtitle string) Option
- func WithTemplate(html string) Option
- func WithTheme(t theme.Theme) Option
- func WithTimeout(d time.Duration) Option
- func WithTitle(title string) Option
- func WithValidator(v mdx.Validator) Option
- func WithVars(vars map[string]string) Option
- func WithVerbose(v bool) Option
- type PDF
- func (p *PDF) Build(ctx context.Context) error
- func (p *PDF) ComposeHTML(docs []*mdx.Document) (string, error)
- func (p *PDF) ParseDir() ([]*mdx.Document, error)
- func (p *PDF) Render(html string) error
- func (p *PDF) Validate(ctx context.Context) ([]mdx.ValidationError, error)
- func (p *PDF) ValidateDoc(doc *mdx.Document) []mdx.ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComposeHTML ¶
func ComposeHTML(docs []*mdx.Document, opts ComposeOptions) (string, error)
Types ¶
type ComposeOptions ¶
func DefaultComposeOptions ¶
func DefaultComposeOptions() ComposeOptions
type Option ¶
type Option func(*PDF)
func WithAuthor ¶
func WithComponent ¶
func WithComponent(name string, handler mdx.ComponentHandler) Option
func WithConfig ¶
func WithHeaderTitle ¶
func WithOutputFile ¶
func WithPaperSize ¶
func WithRenderMargins ¶
func WithSourceDir ¶
func WithSubtitle ¶
func WithTemplate ¶
func WithTimeout ¶
func WithValidator ¶
func WithVerbose ¶
type PDF ¶
type PDF struct {
// contains filtered or unexported fields
}
func (*PDF) ValidateDoc ¶
func (p *PDF) ValidateDoc(doc *mdx.Document) []mdx.ValidationError
Click to show internal directories.
Click to hide internal directories.