gompdf

package module
v0.0.0-...-a95229b Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: MIT Imports: 14 Imported by: 0

README

gompdf

A XML based processor on top of jung-kurt/gofpdf.

Will be soon replaced by xpdf

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultStyle = style.Styles{
	Font: style.Font{
		Family:     "Arial",
		PointSize:  12,
		Style:      style.FontStyleNormal,
		Weight:     style.FontWeightNormal,
		Decoration: style.FontDecorationNormal,
	},
	Box: style.Box{
		Border:  style.Border{Left: 0, Top: 0, Right: 0, Bottom: 0},
		Padding: style.Padding{Left: 0, Top: 0, Right: 0, Bottom: 0},
		Margin:  style.Margin{Left: 0, Top: 0, Right: 0, Bottom: 0},
	},
	Dimension: style.Dimension{
		Width:      -1,
		Height:     -1,
		LineHeight: 1.5,
		OffsetX:    0,
		OffsetY:    0,
	},
	Table: style.Table{
		ColumnWidth: -1,
		ColumnSpan:  1,
	},
	Align: style.Align{
		HAlign: style.HAlignLeft,
		VAlign: style.VAlignTop,
	},
	Color: style.Color{
		Foreground: style.Black,
		Text:       style.Black,
		Background: style.White,
	},
}

Functions

func Logf

func Logf(format string, args ...interface{})

func ParseAndBuild

func ParseAndBuild(source string, target string) error

func RGBAFromHexColor

func RGBAFromHexColor(s string) color.RGBA

Types

type Box

type Box struct {
	Styled
	XMLName xml.Name `xml:"box"`
	Text    string   `xml:",chardata"`
}

type Default

type Default struct {
	XMLName     xml.Name      `xml:"default"`
	Orientation Orientation   `xml:"orientation"`
	Unit        Unit          `xml:"unit"`
	Format      Format        `xml:"format"`
	PageBreaks  PageBreakMode `xml:"page-breaks"`
	PageMargins PageMargins   `xml:"page-margins"`
}

type Document

type Document struct {
	XMLName xml.Name `xml:"document"`
	Meta    Meta     `xml:"meta"`
	Default Default  `xml:"default"`
	Style   string   `xml:"style"`

	Header Instructions `xml:"header"`
	Footer Instructions `xml:"footer"`
	Body   Instructions `xml:"body"`
	// contains filtered or unexported fields
}

func Load

func Load(r io.Reader) (*Document, error)

func LoadFromFile

func LoadFromFile(file string) (*Document, error)

func (*Document) StyleClasses

func (doc *Document) StyleClasses() style.Classes

type Font

type Font struct {
	Styled
	XMLName xml.Name `xml:"font"`
}

type Format

type Format string
const (
	FormatA3     Format = "a3"
	FormatA4     Format = "a4"
	FormatA5     Format = "a5"
	FormatLetter Format = "letter"
	FormatLegal  Format = "legal"
)

type Image

type Image struct {
	Styled
	XMLName xml.Name `xml:"image"`
	Source  string   `xml:",chardata"`
}

type Instruction

type Instruction interface {
	DecodeAttrs(attrs []xml.Attr) error
	Apply(cs style.Classes, styles *style.Styles)
	ApplyWithSelector(sel string, cs style.Classes, styles *style.Styles)
}

type Instructions

type Instructions struct {
	Styled
	// contains filtered or unexported fields
}

func (*Instructions) UnmarshalXML

func (is *Instructions) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type LineFeed

type LineFeed struct {
	NoStyles
	XMLName xml.Name `xml:"lf"`
	Lines   float64  `xml:"lines,attr"`
}

type Meta

type Meta struct {
	XMLName xml.Name `xml:"meta"`
	Author  string   `xml:"author"`
	Creator string   `xml:"creator"`
	Subject string   `xml:"subject"`
}

type NoStyles

type NoStyles struct{}

func (*NoStyles) Apply

func (i *NoStyles) Apply(cs style.Classes, styles *style.Styles)

func (*NoStyles) ApplyWithSelector

func (i *NoStyles) ApplyWithSelector(sel string, cs style.Classes, styles *style.Styles)

func (*NoStyles) DecodeAttrs

func (i *NoStyles) DecodeAttrs(attrs []xml.Attr) error

type Orientation

type Orientation string
const (
	OrientationPortrait  Orientation = "portrait"
	OrientationLandscape Orientation = "landscape"
)

type PageBreakMode

type PageBreakMode string
const (
	PageBreakModeAuto   PageBreakMode = "auto"
	PageBreakModeManual PageBreakMode = "manual"
)

type PageMargins

type PageMargins struct {
	XMLName xml.Name `xml:"page-margins"`
	Left    float64  `xml:"left"`
	Top     float64  `xml:"top"`
	Right   float64  `xml:"right"`
	Bottom  float64  `xml:"bottom"`
}

type ProcessOption

type ProcessOption func(p *Processor) error

func WithCodePage

func WithCodePage(cp string) ProcessOption

func WithFontDir

func WithFontDir(dir string) ProcessOption

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor(doc *Document, options ...ProcessOption) (*Processor, error)

func (*Processor) ColumnWidths

func (p *Processor) ColumnWidths(t *Table, pageWidth float64, tableStyles style.Styles) []float64

func (*Processor) Process

func (p *Processor) Process(w io.Writer) error

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Decode

func (r *Registry) Decode(d *xml.Decoder, start xml.StartElement) (Instruction, error)

func (*Registry) Register

func (r *Registry) Register(prototype Instruction) error

type SetX

type SetX struct {
	NoStyles
	XMLName xml.Name `xml:"set-x"`
	X       float64  `xml:"x,attr"`
}

type SetXY

type SetXY struct {
	NoStyles
	XMLName xml.Name `xml:"set-xy"`
	X       float64  `xml:"x,attr"`
	Y       float64  `xml:"y,attr"`
}

type SetY

type SetY struct {
	NoStyles
	XMLName xml.Name `xml:"set-y"`
	Y       float64  `xml:"y,attr"`
}

type Styled

type Styled struct {
	Appliers []*style.Applier
	Classes  []string
}

func (*Styled) Apply

func (i *Styled) Apply(cs style.Classes, styles *style.Styles)

func (*Styled) ApplyWithSelector

func (i *Styled) ApplyWithSelector(sel string, cs style.Classes, styles *style.Styles)

func (*Styled) DecodeAttrs

func (i *Styled) DecodeAttrs(attrs []xml.Attr) error

type Table

type Table struct {
	Styled
	XMLName xml.Name    `xml:"table"`
	Rows    []*TableRow `xml:"tr"`
}

func (Table) MaxColumnCount

func (t Table) MaxColumnCount() int

func (*Table) UnmarshalXML

func (tab *Table) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type TableCell

type TableCell struct {
	Styled
	XMLName      xml.Name `xml:"td"`
	Content      string   `xml:",chardata"`
	Instructions []Instruction
	// contains filtered or unexported fields
}

func (*TableCell) UnmarshalXML

func (cell *TableCell) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type TableRow

type TableRow struct {
	Styled
	XMLName xml.Name     `xml:"tr"`
	Cells   []*TableCell `xml:"td"`
	// contains filtered or unexported fields
}

func (*TableRow) UnmarshalXML

func (row *TableRow) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Text

type Text struct {
	Styled
	XMLName xml.Name `xml:"text"`
	Text    string   `xml:",chardata"`
}

type Unit

type Unit string
const (
	UnitPt   Unit = "pt"
	UnitMm   Unit = "mm"
	UnitCm   Unit = "cm"
	UnitInch Unit = "in"
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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