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 ¶
- Constants
- func RunServer(port int)
- type ColorTable
- type Document
- func (doc *Document) AddColor(c color.RGBA, name string) *Document
- func (doc *Document) AddFont(family string, charset int, prq int, name string, code string) *Document
- func (doc *Document) AddParagraph() *Paragraph
- func (doc *Document) AddTable() *Table
- func (doc *Document) Export() []byte
- func (doc *Document) GetMaxContentWidth() int
- func (doc *Document) GetTableCellWidthByRatio(tableWidth int, ratio ...float64) []int
- func (doc *Document) NewColorTable() *ColorTable
- func (doc *Document) NewFontTable() *FontTable
- func (doc *Document) SetFormat(format string) *Document
- func (doc *Document) SetMarginBottom(value int) *Document
- func (doc *Document) SetMarginLeft(value int) *Document
- func (doc *Document) SetMarginRight(value int) *Document
- func (doc *Document) SetMarginTop(value int) *Document
- func (doc *Document) SetOrientation(orientation string) *Document
- type FontTable
- type Paragraph
- func (p *Paragraph) AddNewLine() *Paragraph
- func (par *Paragraph) AddPicture(source []byte, format string) *Picture
- func (p *Paragraph) AddText(textStr string, fontSize int, fontCode string, colorCode string) *Text
- func (par *Paragraph) SetAlign(align string) *Paragraph
- func (par *Paragraph) SetIndentFirstLine(value int) *Paragraph
- func (par *Paragraph) SetIndentLeft(value int) *Paragraph
- func (par *Paragraph) SetIndentRight(value int) *Paragraph
- type Picture
- func (pic *Picture) SetCropBottom(cropB int) *Picture
- func (pic *Picture) SetCropLeft(cropL int) *Picture
- func (pic *Picture) SetCropRight(cropR int) *Picture
- func (pic *Picture) SetCropTop(cropT int) *Picture
- func (pic *Picture) SetHeight(height int) *Picture
- func (pic *Picture) SetScaleX(scaleX int) *Picture
- func (pic *Picture) SetScaleY(scaleY int) *Picture
- func (pic *Picture) SetWidth(width int) *Picture
- type Table
- func (t *Table) AddTableRow() *TableRow
- func (t *Table) GetTableCellWidthByRatio(ratio ...float64) []int
- func (t *Table) SetAlign(align string) *Table
- func (t *Table) SetBorder(isBorder bool) *Table
- func (t *Table) SetBorderBottom(isBorder bool) *Table
- func (t *Table) SetBorderColor(color string) *Table
- func (t *Table) SetBorderLeft(isBorder bool) *Table
- func (t *Table) SetBorderRight(isBorder bool) *Table
- func (t *Table) SetBorderStyle(bStyle string) *Table
- func (t *Table) SetBorderTop(isBorder bool) *Table
- func (t *Table) SetBorderWidth(value int) *Table
- func (t *Table) SetMarginBottom(value int) *Table
- func (t *Table) SetMarginLeft(value int) *Table
- func (t *Table) SetMarginRight(value int) *Table
- func (t *Table) SetMarginTop(value int) *Table
- func (t *Table) SetPadding(value int) *Table
- func (t *Table) SetPaddingBottom(value int) *Table
- func (t *Table) SetPaddingLeft(value int) *Table
- func (t *Table) SetPaddingRight(value int) *Table
- func (t *Table) SetPaddingTop(value int) *Table
- func (t *Table) SetWidth(width int) *Table
- type TableCell
- func (dc *TableCell) AddParagraph() *Paragraph
- func (dc *TableCell) SetBackgroundColor(color string) *TableCell
- func (dc *TableCell) SetBorder(isBorder bool) *TableCell
- func (dc *TableCell) SetBorderBottom(value bool) *TableCell
- func (dc *TableCell) SetBorderColor(color string) *TableCell
- func (dc *TableCell) SetBorderLeft(value bool) *TableCell
- func (dc *TableCell) SetBorderRight(value bool) *TableCell
- func (dc *TableCell) SetBorderStyle(bStyle string) *TableCell
- func (dc *TableCell) SetBorderTop(value bool) *TableCell
- func (dc *TableCell) SetBorderWidth(value int) *TableCell
- func (dc *TableCell) SetMarginBottom(value int) *TableCell
- func (dc *TableCell) SetMarginLeft(value int) *TableCell
- func (dc *TableCell) SetMarginRight(value int) *TableCell
- func (dc *TableCell) SetMarginTop(value int) *TableCell
- func (dc *TableCell) SetPadding(value int) *TableCell
- func (dc *TableCell) SetPaddingBottom(value int) *TableCell
- func (dc *TableCell) SetPaddingLeft(value int) *TableCell
- func (dc *TableCell) SetPaddingRight(value int) *TableCell
- func (dc *TableCell) SetPaddingTop(value int) *TableCell
- func (dc *TableCell) SetVAlign(valign string) *TableCell
- func (dc *TableCell) SetVerticalMergedFirst() *TableCell
- func (dc *TableCell) SetVerticalMergedNext() *TableCell
- func (dc *TableCell) SetWidth(cellWidth int) *TableCell
- type TableRow
- func (tr *TableRow) AddDataCell(width int) *TableCell
- func (tr *TableRow) SetBorder(isBorder bool) *TableRow
- func (tr *TableRow) SetBorderBottom(isBorder bool) *TableRow
- func (tr *TableRow) SetBorderColor(color string) *TableRow
- func (tr *TableRow) SetBorderLeft(isBorder bool) *TableRow
- func (tr *TableRow) SetBorderRight(isBorder bool) *TableRow
- func (tr *TableRow) SetBorderStyle(bStyle string) *TableRow
- func (tr *TableRow) SetBorderTop(isBorder bool) *TableRow
- func (tr *TableRow) SetBorderWidth(value int) *TableRow
- type Text
- func (text *Text) SetBold() *Text
- func (text *Text) SetColor(colorCode string) *Text
- func (text *Text) SetItalic() *Text
- func (text *Text) SetRotate() *Text
- func (text *Text) SetScaps() *Text
- func (text *Text) SetStrike() *Text
- func (text *Text) SetSub() *Text
- func (text *Text) SetSuper() *Text
- func (text *Text) SetUnderlining() *Text
Examples ¶
Constants ¶
const ( OrientationPortrait = "orientation_portrait" OrientationLandscape = "orientation_landscape" )
Common paper orientation formats
const ( FormatLetter = "format_Letter" FormatA5 = "format_A5" FormatA4 = "format_A4" FormatA3 = "format_A3" FormatA2 = "format_A2" )
Commont paper formats
const ( AlignCenter = "c" AlignLeft = "l" AlignRight = "r" AlignJustify = "j" AlignDistribute = "d" VAlignTop = "t" VAlignBottom = "b" VAlignMiddle = "c" VAlignJustify = "j" )
Aligning properties
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
const ( ImageFormatJpeg = "jpeg" ImageFormatPng = "png" )
Common image formats
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" ColorTeal = "color_teal" ColorPurple = "color_purple" ColorMaroon = "color_maroon" ColorOlive = "color_olive" ColorGray = "color_gray" ColorSilver = "color_silver" )
List of common colors
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 ¶
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 (*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 ¶
AddParagraph return new instance of Paragraph
func (*Document) GetMaxContentWidth ¶
func (*Document) GetTableCellWidthByRatio ¶
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 ¶
NewFontTable returns new font table for Document
func (*Document) SetMarginBottom ¶
SetMarginBottom sets bottom margin for Document work area
func (*Document) SetMarginLeft ¶
SetMarginLeft sets left margin for Document work area
func (*Document) SetMarginRight ¶
SetMarginRight sets right margin for Document work area
func (*Document) SetMarginTop ¶
SetMarginTop sets top margin for Document work area
func (*Document) SetOrientation ¶
SetOrientation - sets page orientation (portrait, landscape)
type Paragraph ¶
type Paragraph struct {
// contains filtered or unexported fields
}
Paragraph defines Paragraph instances
func (*Paragraph) AddNewLine ¶
AddNewLine adds new line into Paragraph text
func (*Paragraph) AddPicture ¶
AddPicture adds picture
func (*Paragraph) SetIndentFirstLine ¶
SetIndentFirstLine function sets first line indent in twips
func (*Paragraph) SetIndentLeft ¶
SetIndentLeft function sets left indent in twips
func (*Paragraph) SetIndentRight ¶
SetIndentRight function sets right indent in twips
type Picture ¶
type Picture struct {
// contains filtered or unexported fields
}
Main Picture struct
func (*Picture) SetCropBottom ¶
func (*Picture) SetCropLeft ¶
func (*Picture) SetCropRight ¶
func (*Picture) SetCropTop ¶
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a struct for Table.
func (*Table) AddTableRow ¶
AddTableRow returns new Table row instance
func (*Table) GetTableCellWidthByRatio ¶
GetTableCellWidthByRatio returns slice of cell widths
func (*Table) SetBorderBottom ¶
SetBorderBottom function sets Table bottom border presence
func (*Table) SetBorderColor ¶
SetBorderColor function sets color of the Table's border and it's rows and cells
func (*Table) SetBorderLeft ¶
SetBorderLeft function sets Table left border presence
func (*Table) SetBorderRight ¶
SetBorderRight function sets Table right border presence
func (*Table) SetBorderStyle ¶
SetBorderStyle function sets Table left border style
func (*Table) SetBorderTop ¶
SetBorderTop function sets Table top border presence
func (*Table) SetBorderWidth ¶
SetBorderWidth function sets width of the Table's border and it's rows and cells
func (*Table) SetMarginBottom ¶
SetMarginBottom function sets Table bottom margin
func (*Table) SetMarginLeft ¶
SetMarginLeft function sets Table left margin
func (*Table) SetMarginRight ¶
SetMarginRight function sets Table right margin
func (*Table) SetMarginTop ¶
SetMarginTop function sets Table top margin
func (*Table) SetPadding ¶
SetPadding function sets all Table paddings
func (*Table) SetPaddingBottom ¶
SetPaddingBottom function sets Table bottom padding
func (*Table) SetPaddingLeft ¶
SetPaddingLeft function sets Table left margin
func (*Table) SetPaddingRight ¶
SetPaddingRight function sets Table right padding
func (*Table) SetPaddingTop ¶
SetPaddingTop function sets Table top padding
type TableCell ¶
type TableCell struct {
// contains filtered or unexported fields
}
TableCell defines cell properties
func (*TableCell) AddParagraph ¶
AddParagraph creates cell's paragraph
func (*TableCell) SetBackgroundColor ¶
SetBackgroundColor function sets cell's background color
func (*TableCell) SetBorderBottom ¶
SetBorderBottom function sets bottom border to be visible
func (*TableCell) SetBorderColor ¶
SetBorderColor function sets cell's border color
func (*TableCell) SetBorderLeft ¶
SetBorderLeft function set left border to be visible
func (*TableCell) SetBorderRight ¶
SetBorderRight function sets right border to be visible
func (*TableCell) SetBorderStyle ¶
SetBorderStyle function sets cell's border style
func (*TableCell) SetBorderTop ¶
SetBorderTop function sets top border to be visible
func (*TableCell) SetBorderWidth ¶
SetBorderWidth function sets cell's border width px
func (*TableCell) SetMarginBottom ¶
SetMarginBottom function sets this cell's bottom margin
func (*TableCell) SetMarginLeft ¶
SetMarginLeft function sets this cell's left margin
func (*TableCell) SetMarginRight ¶
SetMarginRight function sets this cell's right margin
func (*TableCell) SetMarginTop ¶
SetMarginTop function sets this cell's top margin
func (*TableCell) SetPadding ¶
SetPadding - function sets all paddings to value
func (*TableCell) SetPaddingBottom ¶
SetPaddingBottom function sets this cell's bottom padding
func (*TableCell) SetPaddingLeft ¶
SetPaddingLeft function sets this cell's left padding
func (*TableCell) SetPaddingRight ¶
SetPaddingRight function sets this cell's right padding
func (*TableCell) SetPaddingTop ¶
SetPaddingTop function sets this cell's top padding
func (*TableCell) SetVerticalMergedFirst ¶
SetVerticalMergedFirst sets this cell to be first in vertical merging.
func (*TableCell) SetVerticalMergedNext ¶
SetVerticalMergedNext sets this cell to be not first cell in vertical merging.
type TableRow ¶
type TableRow struct {
// contains filtered or unexported fields
}
TableRow definces Table Row struct
func (*TableRow) AddDataCell ¶
AddDataCell returns new DataCell for current Table row
func (*TableRow) SetBorderBottom ¶
SetBorderBottom function sets bottom border presence
func (*TableRow) SetBorderColor ¶
SetBorderColor sets border color of the row (and recursevely on its cells)
func (*TableRow) SetBorderLeft ¶
SetBorderLeft function sets left border presence
func (*TableRow) SetBorderRight ¶
SetBorderRight function sets right border presence
func (*TableRow) SetBorderStyle ¶
SetBorderStyle function sets border style
func (*TableRow) SetBorderTop ¶
SetBorderTop function sets top border presence
func (*TableRow) SetBorderWidth ¶
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) SetRotate ¶
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) SetUnderlining ¶
SetUnderlining function sets text to Underlining