rtfdoc

package module
v0.8.29 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 15 Imported by: 0

README

RTF Generator

Generates rtf documents

Installation

go get -u github.com/therox/rtf-doc

Usage

Import package

import rtfdoc "github.com/therox/rtf-doc"

Create new document instance

d := rtfdoc.NewDocument()

Setting up header information. First set up color table Set document orientation

d.SetOrientation(rtfdoc.OrientationPortrait)

and document format

d.SetFormat(rtfdoc.FormatA4)

Add first paragraph with string with Times New Roman font ("tnr" as we defined earlier)

p := d.AddParagraph()
p.AddText("Green first string (Times New Roman)", 48, rtfdoc.FontTimesNewRoman, rtfdoc.ColorGreen)

Add more colourful text

d.AddParagraph().AddText("Blue second string (Arial)", 48, rtfdoc.FontArial, rtfdoc.ColorBlue)	
d.AddParagraph().AddText("Red Third string (Comic Sans)", 48, rtfdoc.FontComicSansMS, rtfdoc.ColorRed)

Add table

t := d.AddTable()
t.SetMarginLeft(50).SetMarginRight(50).SetMarginTop(50).SetMarginBottom(50)

t.SetWidth(10000)

Add first row to table

tr := t.AddTableRow()

Get slice of cell widths for current row

cWidth := t.GetTableCellWidthByRatio(1, 3)

First cell

dc := tr.AddDataCell(cWidth[0])

will be vertical for 2 rows

dc.SetVerticalMergedFirst()

Add some text to it

p = dc.AddParagraph()
p.AddText("Blue text with cyrillic support with multiline", 16, rtfdoc.FontComicSansMS, rtfdoc.ColorBlue)
p.AddNewLine()

Add cyrillic (unicode) text

p.AddText("Голубой кириллический текст с переносом строки внутри параграфа", 16, rtfdoc.FontComicSansMS, rtfdoc.ColorBlue)

Set aligning for last paragraph

p.SetAlignt(rtfdoc.AlignJustify)

And one more paragraph

p = dc.AddParagraph()
p.AddText("Another paragraph in vertical cell", 16, rtfdoc.FontComicSansMS, ColorBlue)

with custom indent

p.SetIndentFirstLine(40)

and central aligning

p.SetAlignt(rtfdoc.AlignCenter)

Add last cell for current row

dc = tr.AddDataCell(cWidth[1])
p = dc.AddParagraph().SetAlignt(rtfdoc.AlignCenter)
p.AddText("Green text In top right cell with center align", 16, rtfdoc.FontComicSansMS, rtfdoc.ColorGreen)

Second row

tr = t.AddTableRow()

with 3 cells

cWidth = t.GetTableCellWidthByRatio(1, 1.5, 1.5)

first of which is merged with first cell of the first row

dc = tr.AddDataCell(cWidth[0])
dc.SetVerticalMergedNext()

Second cell

dc = tr.AddDataCell(cWidth[1])
p = dc.AddParagraph().SetAlignt(rtfdoc.AlignRight)
txt := p.AddText("Red text In bottom central cell with right align", 16, rtfdoc.FontArial, rtfdoc.ColorRed)

with bold emphasis

txt.SetBold()

Third cell

dc = tr.AddDataCell(cWidth[2])
p = dc.AddParagraph().SetAlignt(rtfdoc.AlignLeft)
txt = p.AddText("Black text in bottom right cell with left align", 16, rtfdoc.FontComicSansMS, rtfdoc.ColorBlack)

with italic emphasis

txt.SetItalic()

Documentation

Overview

Package rtf-doc provides simple tools for creation and writing rtf documents. It is very early in development and has suck features as work with text (color, font, aligning), tables (merged cells, borders style, thickness and colors), and pictures (jpeg or png format)

Index

Examples

Constants

View Source
const (
	OrientationPortrait  = "orientation_portrait"
	OrientationLandscape = "orientation_landscape"
)

Common paper orientation formats

View Source
const (
	FormatLetter = "format_Letter"
	FormatA5     = "format_A5"
	FormatA4     = "format_A4"
	FormatA3     = "format_A3"
	FormatA2     = "format_A2"
)

Commont paper formats

View Source
const (
	AlignCenter     = "c"
	AlignLeft       = "l"
	AlignRight      = "r"
	AlignJustify    = "j"
	AlignDistribute = "d"

	VAlignTop     = "t"
	VAlignBottom  = "b"
	VAlignMiddle  = "c"
	VAlignJustify = "j"
)

Aligning properties

View Source
const (
	BorderSingleThickness     = "s"
	BorderDoubleThickness     = "th"
	BorderShadowed            = "sh"
	BorderDouble              = "db"
	BorderDotted              = "dot"
	BorderDashed              = "dash"
	BorderHairline            = "hair"
	BorderInset               = "inset"
	BorderDashSmall           = "dashsm"
	BorderDotDash             = "dashd"
	BorderDotDotDash          = "dashdd"
	BorderOutset              = "outset"
	BorderTriple              = "triple"
	BorderThickThinSmall      = "tnthsg"
	BorderThinThickSmall      = "thtnsg"
	BorderThickThinMedium     = "tnthmg"
	BorderThinThickMedium     = "thtnmg"
	BorderThinThickThinMedium = "tnthtnmg"
	BorderThickThinLarge      = "tnthlg"
	BorderThinThickLarge      = "thtnlg"
	BorderThinThickThinLarge  = "tnthtnlg"
	BorderWavy                = "wavy"
	BorderWavyDouble          = "wavydb"
	BorderStripped            = "dashdotstr"
	BorderEmboss              = "emboss"
	BorderEngrave             = "engrave"
)

Common styles of border

View Source
const (
	ImageFormatJpeg = "jpeg"
	ImageFormatPng  = "png"
)

Common image formats

View Source
const (
	ColorBlack   = "color_black"
	ColorBlue    = "color_blue"
	ColorAqua    = "color_aqua"
	ColorLime    = "color_lime"
	ColorGreen   = "color_green"
	ColorMagenta = "color_magenta"
	ColorRed     = "color_red"
	ColorYellow  = "color_yellow"
	ColorWhite   = "color_white"
	ColorNavy    = "color_navy"
	ColorTeal    = "color_teal"
	ColorPurple  = "color_purple"
	ColorMaroon  = "color_maroon"
	ColorOlive   = "color_olive"
	ColorGray    = "color_gray"
	ColorSilver  = "color_silver"
)

List of common colors

View Source
const (
	FontTimesNewRoman = "font_times_new_roman"
	FontSymbol        = "font_symbol"
	FontArial         = "font_arial"
	FontComicSansMS   = "font_comic_sans_ms"
	FontCourierNew    = "font_courier_new"
)

Common fonts

Variables

This section is empty.

Functions

func RunServer

func RunServer(port int)

RunServer run listener server for doc generate

Types

type ColorTable

type ColorTable []colorItem

ColorTable defines color table

func (*ColorTable) AddColor

func (cTbl *ColorTable) AddColor(c color.RGBA, name string) *ColorTable

AddColor adds color to color table

type Document

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

Document - main document struct

Example
package main

import (
	"fmt"

	rtfdoc "github.com/therox/rtf-doc"
)

func main() {
	doc := rtfdoc.NewDocument()
	doc.AddParagraph().SetAlignt(rtfdoc.AlignCenter).AddText("Hello, world!", 14, rtfdoc.FontTimesNewRoman, rtfdoc.ColorAqua)
	bs := doc.Export()
	fmt.Println(string(bs))
}
Output:

func NewDocument

func NewDocument() *Document

NewDocument returns new rtf Document instance

func (*Document) AddColor

func (doc *Document) AddColor(c color.RGBA, name string) *Document

AddColor function adds colot to Document color table

func (*Document) AddFont

func (doc *Document) AddFont(family string, charset int, prq int, name string, code string) *Document

AddFont function adds font to Document header

func (*Document) AddParagraph

func (doc *Document) AddParagraph() *Paragraph

AddParagraph return new instance of Paragraph

func (*Document) AddTable

func (doc *Document) AddTable() *Table

AddTable returns Table instance

func (*Document) Export

func (doc *Document) Export() []byte

Export exports Document

func (*Document) GetMaxContentWidth

func (doc *Document) GetMaxContentWidth() int

func (*Document) GetTableCellWidthByRatio

func (doc *Document) GetTableCellWidthByRatio(tableWidth int, ratio ...float64) []int

GetTableCellWidthByRatio - returns slice of cell widths from cells ratios

func (*Document) NewColorTable

func (doc *Document) NewColorTable() *ColorTable

NewColorTable returns new color table for Document

func (*Document) NewFontTable

func (doc *Document) NewFontTable() *FontTable

NewFontTable returns new font table for Document

func (*Document) SetFormat

func (doc *Document) SetFormat(format string) *Document

SetFormat sets page format (A2, A3, A4)

func (*Document) SetMarginBottom

func (doc *Document) SetMarginBottom(value int) *Document

SetMarginBottom sets bottom margin for Document work area

func (*Document) SetMarginLeft

func (doc *Document) SetMarginLeft(value int) *Document

SetMarginLeft sets left margin for Document work area

func (*Document) SetMarginRight

func (doc *Document) SetMarginRight(value int) *Document

SetMarginRight sets right margin for Document work area

func (*Document) SetMarginTop

func (doc *Document) SetMarginTop(value int) *Document

SetMarginTop sets top margin for Document work area

func (*Document) SetOrientation

func (doc *Document) SetOrientation(orientation string) *Document

SetOrientation - sets page orientation (portrait, landscape)

type FontTable

type FontTable []font

FontTable defines font table

func NewFontTable

func NewFontTable() *FontTable

NewFontTable - returns new font table

func (*FontTable) AddFont

func (ft *FontTable) AddFont(family string, charset int, prq int, name string, code string) *FontTable

AddFont returns font instance

type Paragraph

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

Paragraph defines Paragraph instances

func (*Paragraph) AddNewLine

func (p *Paragraph) AddNewLine() *Paragraph

AddNewLine adds new line into Paragraph text

func (*Paragraph) AddPicture

func (par *Paragraph) AddPicture(source []byte, format string) *Picture

AddPicture adds picture

func (*Paragraph) AddText

func (p *Paragraph) AddText(textStr string, fontSize int, fontCode string, colorCode string) *Text

AddText returns new text instance

func (*Paragraph) SetAlign

func (par *Paragraph) SetAlign(align string) *Paragraph

SetAlign sets Paragraph align (c/center, l/left, r/right, j/justify)

func (*Paragraph) SetIndentFirstLine

func (par *Paragraph) SetIndentFirstLine(value int) *Paragraph

SetIndentFirstLine function sets first line indent in twips

func (*Paragraph) SetIndentLeft

func (par *Paragraph) SetIndentLeft(value int) *Paragraph

SetIndentLeft function sets left indent in twips

func (*Paragraph) SetIndentRight

func (par *Paragraph) SetIndentRight(value int) *Paragraph

SetIndentRight function sets right indent in twips

type Picture

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

Main Picture struct

func (*Picture) SetCropBottom

func (pic *Picture) SetCropBottom(cropB int) *Picture

func (*Picture) SetCropLeft

func (pic *Picture) SetCropLeft(cropL int) *Picture

func (*Picture) SetCropRight

func (pic *Picture) SetCropRight(cropR int) *Picture

func (*Picture) SetCropTop

func (pic *Picture) SetCropTop(cropT int) *Picture

func (*Picture) SetHeight

func (pic *Picture) SetHeight(height int) *Picture

func (*Picture) SetScaleX

func (pic *Picture) SetScaleX(scaleX int) *Picture

func (*Picture) SetScaleY

func (pic *Picture) SetScaleY(scaleY int) *Picture

func (*Picture) SetWidth

func (pic *Picture) SetWidth(width int) *Picture

type Table

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

Table is a struct for Table.

func (*Table) AddTableRow

func (t *Table) AddTableRow() *TableRow

AddTableRow returns new Table row instance

func (*Table) GetTableCellWidthByRatio

func (t *Table) GetTableCellWidthByRatio(ratio ...float64) []int

GetTableCellWidthByRatio returns slice of cell widths

func (*Table) SetAlign

func (t *Table) SetAlign(align string) *Table

SetAlign sets Table aligning (c/center, l/left, r/right)

func (*Table) SetBorder

func (t *Table) SetBorder(isBorder bool) *Table

SetBorder function sets Table bottom border presence

func (*Table) SetBorderBottom

func (t *Table) SetBorderBottom(isBorder bool) *Table

SetBorderBottom function sets Table bottom border presence

func (*Table) SetBorderColor

func (t *Table) SetBorderColor(color string) *Table

SetBorderColor function sets color of the Table's border and it's rows and cells

func (*Table) SetBorderLeft

func (t *Table) SetBorderLeft(isBorder bool) *Table

SetBorderLeft function sets Table left border presence

func (*Table) SetBorderRight

func (t *Table) SetBorderRight(isBorder bool) *Table

SetBorderRight function sets Table right border presence

func (*Table) SetBorderStyle

func (t *Table) SetBorderStyle(bStyle string) *Table

SetBorderStyle function sets Table left border style

func (*Table) SetBorderTop

func (t *Table) SetBorderTop(isBorder bool) *Table

SetBorderTop function sets Table top border presence

func (*Table) SetBorderWidth

func (t *Table) SetBorderWidth(value int) *Table

SetBorderWidth function sets width of the Table's border and it's rows and cells

func (*Table) SetMarginBottom

func (t *Table) SetMarginBottom(value int) *Table

SetMarginBottom function sets Table bottom margin

func (*Table) SetMarginLeft

func (t *Table) SetMarginLeft(value int) *Table

SetMarginLeft function sets Table left margin

func (*Table) SetMarginRight

func (t *Table) SetMarginRight(value int) *Table

SetMarginRight function sets Table right margin

func (*Table) SetMarginTop

func (t *Table) SetMarginTop(value int) *Table

SetMarginTop function sets Table top margin

func (*Table) SetPadding

func (t *Table) SetPadding(value int) *Table

SetPadding function sets all Table paddings

func (*Table) SetPaddingBottom

func (t *Table) SetPaddingBottom(value int) *Table

SetPaddingBottom function sets Table bottom padding

func (*Table) SetPaddingLeft

func (t *Table) SetPaddingLeft(value int) *Table

SetPaddingLeft function sets Table left margin

func (*Table) SetPaddingRight

func (t *Table) SetPaddingRight(value int) *Table

SetPaddingRight function sets Table right padding

func (*Table) SetPaddingTop

func (t *Table) SetPaddingTop(value int) *Table

SetPaddingTop function sets Table top padding

func (*Table) SetWidth

func (t *Table) SetWidth(width int) *Table

SetWidth sets width of Table

type TableCell

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

TableCell defines cell properties

func (*TableCell) AddParagraph

func (dc *TableCell) AddParagraph() *Paragraph

AddParagraph creates cell's paragraph

func (*TableCell) SetBackgroundColor

func (dc *TableCell) SetBackgroundColor(color string) *TableCell

SetBackgroundColor function sets cell's background color

func (*TableCell) SetBorder

func (dc *TableCell) SetBorder(isBorder bool) *TableCell

SetBorder function sets bottom borders

func (*TableCell) SetBorderBottom

func (dc *TableCell) SetBorderBottom(value bool) *TableCell

SetBorderBottom function sets bottom border to be visible

func (*TableCell) SetBorderColor

func (dc *TableCell) SetBorderColor(color string) *TableCell

SetBorderColor function sets cell's border color

func (*TableCell) SetBorderLeft

func (dc *TableCell) SetBorderLeft(value bool) *TableCell

SetBorderLeft function set left border to be visible

func (*TableCell) SetBorderRight

func (dc *TableCell) SetBorderRight(value bool) *TableCell

SetBorderRight function sets right border to be visible

func (*TableCell) SetBorderStyle

func (dc *TableCell) SetBorderStyle(bStyle string) *TableCell

SetBorderStyle function sets cell's border style

func (*TableCell) SetBorderTop

func (dc *TableCell) SetBorderTop(value bool) *TableCell

SetBorderTop function sets top border to be visible

func (*TableCell) SetBorderWidth

func (dc *TableCell) SetBorderWidth(value int) *TableCell

SetBorderWidth function sets cell's border width px

func (*TableCell) SetMarginBottom

func (dc *TableCell) SetMarginBottom(value int) *TableCell

SetMarginBottom function sets this cell's bottom margin

func (*TableCell) SetMarginLeft

func (dc *TableCell) SetMarginLeft(value int) *TableCell

SetMarginLeft function sets this cell's left margin

func (*TableCell) SetMarginRight

func (dc *TableCell) SetMarginRight(value int) *TableCell

SetMarginRight function sets this cell's right margin

func (*TableCell) SetMarginTop

func (dc *TableCell) SetMarginTop(value int) *TableCell

SetMarginTop function sets this cell's top margin

func (*TableCell) SetPadding

func (dc *TableCell) SetPadding(value int) *TableCell

SetPadding - function sets all paddings to value

func (*TableCell) SetPaddingBottom

func (dc *TableCell) SetPaddingBottom(value int) *TableCell

SetPaddingBottom function sets this cell's bottom padding

func (*TableCell) SetPaddingLeft

func (dc *TableCell) SetPaddingLeft(value int) *TableCell

SetPaddingLeft function sets this cell's left padding

func (*TableCell) SetPaddingRight

func (dc *TableCell) SetPaddingRight(value int) *TableCell

SetPaddingRight function sets this cell's right padding

func (*TableCell) SetPaddingTop

func (dc *TableCell) SetPaddingTop(value int) *TableCell

SetPaddingTop function sets this cell's top padding

func (*TableCell) SetVAlign

func (dc *TableCell) SetVAlign(valign string) *TableCell

SetVAlign sets align

func (*TableCell) SetVerticalMergedFirst

func (dc *TableCell) SetVerticalMergedFirst() *TableCell

SetVerticalMergedFirst sets this cell to be first in vertical merging.

func (*TableCell) SetVerticalMergedNext

func (dc *TableCell) SetVerticalMergedNext() *TableCell

SetVerticalMergedNext sets this cell to be not first cell in vertical merging.

func (*TableCell) SetWidth

func (dc *TableCell) SetWidth(cellWidth int) *TableCell

SetWidth sets width of the cell

type TableRow

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

TableRow definces Table Row struct

func (*TableRow) AddDataCell

func (tr *TableRow) AddDataCell(width int) *TableCell

AddDataCell returns new DataCell for current Table row

func (*TableRow) SetBorder

func (tr *TableRow) SetBorder(isBorder bool) *TableRow

SetBorder function sets bottom borders

func (*TableRow) SetBorderBottom

func (tr *TableRow) SetBorderBottom(isBorder bool) *TableRow

SetBorderBottom function sets bottom border presence

func (*TableRow) SetBorderColor

func (tr *TableRow) SetBorderColor(color string) *TableRow

SetBorderColor sets border color of the row (and recursevely on its cells)

func (*TableRow) SetBorderLeft

func (tr *TableRow) SetBorderLeft(isBorder bool) *TableRow

SetBorderLeft function sets left border presence

func (*TableRow) SetBorderRight

func (tr *TableRow) SetBorderRight(isBorder bool) *TableRow

SetBorderRight function sets right border presence

func (*TableRow) SetBorderStyle

func (tr *TableRow) SetBorderStyle(bStyle string) *TableRow

SetBorderStyle function sets border style

func (*TableRow) SetBorderTop

func (tr *TableRow) SetBorderTop(isBorder bool) *TableRow

SetBorderTop function sets top border presence

func (*TableRow) SetBorderWidth

func (tr *TableRow) SetBorderWidth(value int) *TableRow

SetBorderWidth sets border width (and recursevely on its cells)

type Text

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

Text defines Text instances

func (*Text) SetBold

func (text *Text) SetBold() *Text

SetBold function sets text to Bold

func (*Text) SetColor

func (text *Text) SetColor(colorCode string) *Text

SetColor sets text color

func (*Text) SetItalic

func (text *Text) SetItalic() *Text

SetItalic function sets text to Italic

func (*Text) SetRotate

func (text *Text) SetRotate() *Text

SetRotate function rotates Text so it flows in a direction opposite to that of the main document (Horizontal in vertical and vertical in horizontal)

func (*Text) SetScaps

func (text *Text) SetScaps() *Text

SetScaps function sets text to Scaps

func (*Text) SetStrike

func (text *Text) SetStrike() *Text

SetStrike function sets text to Strike

func (*Text) SetSub

func (text *Text) SetSub() *Text

SetSub function sets text to Sub

func (*Text) SetSuper

func (text *Text) SetSuper() *Text

SetSuper function sets text to Super

func (*Text) SetUnderlining

func (text *Text) SetUnderlining() *Text

SetUnderlining function sets text to Underlining

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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