docx

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StartPlace = "{{"
	EndPlace   = "}}"
)
View Source
var (
	ErrCouldntFindWordDoc = errors.New("invalid docx file, couldn't find word document xml")
	ErrImageNotFound      = errors.New("image not found")
	ErrFatalFailure       = errors.New("fatal failure")
)

Functions

func NilReplacerFunc added in v1.1.3

func NilReplacerFunc(_ string) (string, bool)

Types

type Char

type Char struct {
	Rune rune
	T    *xml.UniversalElement
	R    *xml.UniversalElement
	P    *xml.UniversalElement
}

type CharList

type CharList struct {
	Head  *CharNode
	Tail  *CharNode
	First *CharNode
}

func (*CharList) Current

func (l *CharList) Current() *Char

func (*CharList) GoToFirst

func (l *CharList) GoToFirst()

func (*CharList) Insert

func (l *CharList) Insert(r *Char)

func (*CharList) InsertBefore

func (l *CharList) InsertBefore(r *Char)

func (*CharList) Len

func (l *CharList) Len() int

func (*CharList) LoadFromElement

func (l *CharList) LoadFromElement(con *xml.UniversalElement)

func (*CharList) LookAhead

func (l *CharList) LookAhead(t int) string

func (*CharList) LookAheadTill

func (l *CharList) LookAheadTill(delim string) (string, error)

func (*CharList) Next

func (l *CharList) Next() *Char

func (*CharList) Prev

func (l *CharList) Prev() *Char

func (*CharList) Remove

func (l *CharList) Remove(t int) error

func (*CharList) Replace

func (l *CharList) Replace(rf ReplacerFunc) error

func (*CharList) Seek

func (l *CharList) Seek(t int)

func (*CharList) SeekTill

func (l *CharList) SeekTill(delim string) error

func (*CharList) String

func (l *CharList) String() string

func (*CharList) ToParagraphList

func (l *CharList) ToParagraphList() []*xml.UniversalElement

type CharNode

type CharNode struct {
	Char *Char
	Prev *CharNode
	Next *CharNode
}

type DocImage added in v1.1.1

type DocImage struct {
	Name        string
	Fingerprint string
}

func NewDocImage added in v1.1.2

func NewDocImage(file *zip.File) DocImage

type DocImageList added in v1.1.1

type DocImageList map[DocImage]io.Reader

func (DocImageList) Has added in v1.1.1

func (d DocImageList) Has(fingerprint string) bool

type Docx

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

func NewDocxFromStream added in v1.1.2

func NewDocxFromStream(data io.ReaderAt, size int64) (*Docx, error)

NewDocxFromFile creates a new Docx from a io.ReaderAt

func (*Docx) Replace

func (d *Docx) Replace(f ReplacerFunc) error

Replace replaces all occurrences of the given string with the given string

func (*Docx) ReplaceImageByFingerPrint added in v1.1.1

func (d *Docx) ReplaceImageByFingerPrint(oldImageFingerprint string, newImage io.Reader) (err error)

ReplaceImageByFingerPrint replaces the image with the given fingerprint

func (*Docx) ReplaceImageByImageName added in v1.1.1

func (d *Docx) ReplaceImageByImageName(oldImageName string, newImage io.Reader) (err error)

ReplaceImageByImageName replaces the image with the given name

func (*Docx) Save

func (d *Docx) Save(ioWriter io.Writer) (err error)

Save writes the docx file to the given io.Writer

func (*Docx) WriteToFile added in v1.1.0

func (d *Docx) WriteToFile(path string) (err error)

WriteToFile writes the docx file to the given path

type Paragraph

type Paragraph struct {
	ControlR *xml.UniversalElement
	ControlT *xml.UniversalElement
	xml.UniversalElement
}

func NewParagraph

func NewParagraph(p, r, t *xml.UniversalElement) *Paragraph

func (*Paragraph) Insert

func (p *Paragraph) Insert(char *Char)

func (*Paragraph) ToUniversal

func (p *Paragraph) ToUniversal() *xml.UniversalElement

type Processor

type Processor struct {
	Document *xml.UniversalElement
}

func (*Processor) LoadAndReplace

func (p *Processor) LoadAndReplace(inp []byte, f ReplacerFunc) ([]byte, error)

func (*Processor) LoadElement

func (p *Processor) LoadElement(doc *xml.UniversalElement)

func (*Processor) ProccessReplace

func (p *Processor) ProccessReplace(con *xml.UniversalElement, repf ReplacerFunc) error

func (*Processor) Replace

func (p *Processor) Replace(repfunc ReplacerFunc) ([]byte, error)

func (*Processor) WalkAndReplace

func (p *Processor) WalkAndReplace(start *xml.UniversalElement, repf ReplacerFunc) error

type ReplacerFunc

type ReplacerFunc func(placeholder string) (string, bool)

func NewStructReplacerFunc added in v1.1.2

func NewStructReplacerFunc(model interface{}) (ReplacerFunc, error)

type Template

type Template struct {
	File *Docx
}

func NewTemplate

func NewTemplate(reader io.Reader) (*Template, error)

func (*Template) ExecuteToPDF

func (t *Template) ExecuteToPDF(model interface{}, exts ...TemplateExecuteExtension) ([]byte, error)

func (*Template) ExecuteToWriter

func (t *Template) ExecuteToWriter(model interface{}, writer io.Writer, exts ...TemplateExecuteExtension) error

type TemplateExecuteExtension added in v1.1.2

type TemplateExecuteExtension func(*Template) error

func WithImageReplaceByFingerprint added in v1.1.2

func WithImageReplaceByFingerprint(ims map[string]io.Reader) TemplateExecuteExtension

func WithImageReplaceByName added in v1.1.2

func WithImageReplaceByName(ims map[string]io.Reader) TemplateExecuteExtension

Jump to

Keyboard shortcuts

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