Documentation
¶
Overview ¶
Package pdf renders HTML documents to PDF using Chromium.
Package pdf renders HTML documents to PDF using Chromium.
Index ¶
- func CheckChromiumAvailable() error
- type Generator
- type GeneratorOption
- func WithDocumentOutline(enable bool) GeneratorOption
- func WithHeaderFooter(enable bool) GeneratorOption
- func WithMargins(left, right, top, bottom float64) GeneratorOption
- func WithPageSize(width, height float64) GeneratorOption
- func WithPrintBackground(print bool) GeneratorOption
- func WithTaggedPDF(enable bool) GeneratorOption
- func WithTimeout(d time.Duration) GeneratorOption
- type MockGenerator
- type PDFRenderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckChromiumAvailable ¶
func CheckChromiumAvailable() error
CheckChromiumAvailable reports whether Chrome or Chromium is installed.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator converts HTML into PDF files.
func NewGenerator ¶
func NewGenerator(opts ...GeneratorOption) *Generator
NewGenerator creates a PDF generator. By default, it generates a document outline (clickable bookmarks) and tagged PDF.
type GeneratorOption ¶
type GeneratorOption func(*Generator)
GeneratorOption customizes a PDF generator.
func WithDocumentOutline ¶
func WithDocumentOutline(enable bool) GeneratorOption
WithDocumentOutline toggles PDF bookmark/outline generation from heading hierarchy. Enabled by default. Requires Chrome 128+ for full support.
func WithHeaderFooter ¶
func WithHeaderFooter(enable bool) GeneratorOption
WithHeaderFooter toggles header and footer rendering.
func WithMargins ¶
func WithMargins(left, right, top, bottom float64) GeneratorOption
WithMargins sets page margins in millimeters.
func WithPageSize ¶
func WithPageSize(width, height float64) GeneratorOption
WithPageSize sets the page size in millimeters.
func WithPrintBackground ¶
func WithPrintBackground(print bool) GeneratorOption
WithPrintBackground toggles background printing.
func WithTaggedPDF ¶
func WithTaggedPDF(enable bool) GeneratorOption
WithTaggedPDF toggles tagged (accessible) PDF generation. Enabled by default. Tagged PDFs include structural metadata for screen readers.
func WithTimeout ¶
func WithTimeout(d time.Duration) GeneratorOption
WithTimeout sets the operation timeout.
type MockGenerator ¶
type MockGenerator struct {
GenerateCalled bool
LastHTMLContent string
LastOutputPath string
GenerateError error // Set this to simulate errors
}
MockGenerator is a test double that writes a minimal valid PDF header without requiring Chromium. Use it in tests to verify PDF generation flow without external dependencies.
func (*MockGenerator) Generate ¶
func (m *MockGenerator) Generate(htmlContent string, outputPath string) error
Generate records the call arguments and writes a minimal PDF file.
func (*MockGenerator) GenerateFromFile ¶
func (m *MockGenerator) GenerateFromFile(htmlFilePath string, outputPath string) error
GenerateFromFile reads the HTML file and calls Generate with its content.