core

package
v0.0.0-...-f60ce48 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// A PDF page is divided into three parts, the header(Header), the footer(Footer) and
	// the main body(Detail).
	//
	// Each part has its own executor. The main actuator is necessary because it is the most
	// important content that constitutes the PDF page.
	Header = "Header"
	Footer = "Footer"
	Detail = "Detail"

	// flags
	Flag_AutoAddNewPage = "AutoAddNewPage"
	Flag_ResetPageNo    = "ResetPageNo"
)

Variables

This section is empty.

Functions

func Register

func Register(size string, config *Config)

Register create self pdf config

Types

type CallBack

type CallBack func(report *Report)

type Cell

type Cell interface {
	GenerateAtomicCell(height float64) (writed, remain int, err error) // 写入的行数, 剩余的行数,错误
	TryGenerateAtomicCell(height float64) (writed, remain int)         // 尝试写入
	GetHeight() (height float64)                                       // 当前cell的height
	GetLastHeight() (height float64)                                   // 最近一次cell的height
}

type Config

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

the units of below is pixels.

func NewConfig

func NewConfig(width, height float64, padingH, padingV float64) (*Config, error)

Params width, height is pdf page width and height Params padingH, padingV is pdf horizontal and vertical padding The units of the above parameters are pixels. Params width must more than 2*padingH, and height must more 2*padingV

func (*Config) GetEnd

func (config *Config) GetEnd() (x, y float64)

func (*Config) GetStart

func (config *Config) GetStart() (x, y float64)

Get pdf page start position, from the position you can write the pdf body content.

func (*Config) GetWidthAndHeight

func (config *Config) GetWidthAndHeight() (width, height float64)

type Converter

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

Converter is a bridge to third-party gopdf. The content generated by the user by calling a simple interface is converted from pdf to complex content, and finally a pdf file is generated.

func (*Converter) AddAtomicCell

func (convert *Converter) AddAtomicCell(cell string)

Add a atomicCell to atomicCells

func (*Converter) AddFont

func (convert *Converter) AddFont()

add fonts

func (*Converter) BackgroundColor

func (convert *Converter) BackgroundColor(line string, elements []string)

backgroup color

func (*Converter) Cell

func (convert *Converter) Cell(line string, elements []string)

Clell ["C", family, size, x, y, content] // Start writing text from position (x,y) ["CL", x, y, content] // Start writing text from position (x,y) ["CR", x, y, w, content] // Write text of w length from right to left

func (*Converter) CompressLevel

func (convert *Converter) CompressLevel(level int)

func (*Converter) Execute

func (convert *Converter) Execute()

Generate a pdf file of the content recorded in atomicCells.

func (convert *Converter) ExternalLink(line string, elements []string)

external link ["EL", x, y, w, h, content, link] // Start writing text from (x,y) and add external links

func (*Converter) Font

func (convert *Converter) Font(line string, elements []string)

Set Font used for the current text ["", "family", "style", "size"] style: "" or "U", ("B", "I")("B" means "Bold", "I" means "Italic", these font self support)

func (*Converter) GetAutomicCells

func (convert *Converter) GetAutomicCells() []string

GetAtomicCells, get atomicCells

func (*Converter) GetBytesPdf

func (convert *Converter) GetBytesPdf() (ret []byte)

func (*Converter) GetXY

func (convert *Converter) GetXY() (x, y float64)

func (*Converter) Grey

func (convert *Converter) Grey(line string, elements []string)

Set the gray scale of the stroke Or Set the gray scale of the fill ["GF|GS", grayScale] grayScale: 0.0 到 1.0

func (*Converter) Image

func (convert *Converter) Image(line string, elements []string)

image ["I", path, x, y, x1, y2]

func (*Converter) InternalLinkAnchor

func (convert *Converter) InternalLinkAnchor(line string, elements []string)

Internal link, anchor ["ILA", x, y, w, h, content, anchor]

func (convert *Converter) InternalLinkLink(line string, elements []string)

Internal link, link ["ILL", x, y, w content, anchor]

func (*Converter) Line

func (convert *Converter) Line(line string, elements []string)

line ["L", x1, y1, x2, y2], Line between any two points ["LH", x1, y1, x2], Horizontal line ["LV", x1, y2, y2], Vertical line

["LT", "dashed|dotted|straight", w] Lines with a specific style(dashed,dotted,straight) dashed: ---- dotted: .... straight: ___

func (*Converter) LineColor

func (convert *Converter) LineColor(line string, elements []string)

line color ["", R, G, B]

func (*Converter) Margin

func (convert *Converter) Margin(line string, eles []string)

func (*Converter) MeasureTextWidth

func (convert *Converter) MeasureTextWidth(text string) float64

func (*Converter) NewPage

func (convert *Converter) NewPage(line string, elements []string)

add new page

func (*Converter) NoCompression

func (convert *Converter) NoCompression()

func (*Converter) Oval

func (convert *Converter) Oval(line string, elements []string)

oval ["", x1, y1, x2, y2]

func (*Converter) Page

func (convert *Converter) Page(line string, elements []string)

Page [P, mm|pt|in, A4, P|L] mm|pt|in, Indicates the unit of size, respectively representing millimeters, pixels, and feet P|L, Page layout, namely Portait, Landscape

func (*Converter) ReadFile

func (convert *Converter) ReadFile(fileName string) error

ReadFile parse file content to atomicCells Generate pdf files for text content from already saved atomicCells, generally used for debugging.

func (*Converter) Rect

func (convert *Converter) Rect(line string, eles []string)

rectangle ["R", x1, y1, x2, y2]

func (*Converter) SetAutomicCells

func (convert *Converter) SetAutomicCells(cells []string)

SetAtomicCells, set atomicCells (use caution)

func (*Converter) SetFont

func (convert *Converter) SetFont(family, style string, size int)

func (*Converter) TextColor

func (convert *Converter) TextColor(line string, elements []string)

text color ["", R, G, B]

func (*Converter) WritePdf

func (convert *Converter) WritePdf(filepath string)

type Executor

type Executor func(report *Report)

type Font

type Font struct {
	Family string // Font family

	// Font style, currently supported "", "U", "B", "I", where "B", "I" need to be defined by
	// the font itself
	Style string

	Size int // Font size
}

type FontMap

type FontMap struct {
	FontName string
	FileName string
}

type List

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

func (*List) Add

func (list *List) Add(value interface{})

func (*List) Get

func (list *List) Get(i int) interface{}

func (*List) GetAsArray

func (list *List) GetAsArray() []interface{}

func (*List) Reset

func (list *List) Reset()

func (*List) Size

func (list *List) Size() int

type Report

type Report struct {
	FisrtPageNeedHeader bool // Wheather the first page need to execute the header
	FisrtPageNeedFooter bool // Wheather the first page need to execute the header
	Vars                map[string]string
	// contains filtered or unexported fields
}

func CreateReport

func CreateReport() *Report

func (*Report) AddCallBack

func (report *Report) AddCallBack(callback CallBack)

func (*Report) AddNewPage

func (report *Report) AddNewPage(resetpageNo bool)

添加新的页面

func (*Report) BackgroundColor

func (report *Report) BackgroundColor(x, y, w, h float64, bgcolor string, lines string, lcolor ...string)

bgcolor: background color. style is "r,g,b", eg. "1,1,1" is black lines: whether border lines are needed. eg, "0000" is not needed, "1111" is needed, "0110" is required for TOP, RIGHT lines. lcolor: line color, style is "r,g,b", eg. "1,1,1" is black

func (*Report) Cell

func (report *Report) Cell(x float64, y float64, content string)

写入字符串内容

func (*Report) CellGray

func (report *Report) CellGray(x float64, y float64, content string, grayScale float64)

func (*Report) CellRight

func (report *Report) CellRight(x float64, y float64, w float64, content string)

func (*Report) CompressLevel

func (report *Report) CompressLevel(level int)

*************************************************************** Compression level:

-2: Only Huffman compression is used,
-1: Default value, compression level 6
0:  Not compress,
1:  The fastest compression, but the compression ratio is not the best
9:  Maximum compression, but the execution efficiency is also the slowest

***************************************************************

func (*Report) Execute

func (report *Report) Execute(filepath string)

Execute, execute Executors and generate PDF file

func (report *Report) ExternalLink(x, y, th float64, content, link string)

外部链接

func (*Report) Font

func (report *Report) Font(fontName string, size int, style string)

注册当前字体

func (*Report) GetAtomicCells

func (report *Report) GetAtomicCells() *[]string

获取底层的所有的原子单元内容

func (*Report) GetBytesPdf

func (report *Report) GetBytesPdf() (ret []byte)

GetBytesPdf, get PDF file content

func (*Report) GetConfig

func (report *Report) GetConfig() Config

func (*Report) GetContentWidthAndHeight

func (report *Report) GetContentWidthAndHeight() (width, height float64)

func (*Report) GetCurrentPageNo

func (report *Report) GetCurrentPageNo() int

获取当前页面编号

func (*Report) GetPageEndXY

func (report *Report) GetPageEndXY() (x, y float64)

func (*Report) GetPageStartXY

func (report *Report) GetPageStartXY() (x, y float64)

func (*Report) GetXY

func (report *Report) GetXY() (x, y float64)

func (*Report) Image

func (report *Report) Image(path string, x1 float64, y1 float64, x2 float64, y2 float64)

图片

func (*Report) InternalLinkAnchor

func (report *Report) InternalLinkAnchor(x, y, th float64, content, anchor string)
func (report *Report) InternalLinkLink(x, y float64, content, anchor string)

func (*Report) Line

func (report *Report) Line(x1 float64, y1 float64, x2 float64, y2 float64)

func (*Report) LineColor

func (report *Report) LineColor(red int, green int, blue int)

func (*Report) LineDefaultColor

func (report *Report) LineDefaultColor()

func (*Report) LineGrayColor

func (report *Report) LineGrayColor(x, y float64, w, h float64, gray float64)

线条灰度

func (*Report) LineH

func (report *Report) LineH(x1 float64, y float64, x2 float64)

func (*Report) LineType

func (report *Report) LineType(ltype string, width float64)

划线

func (*Report) LineV

func (report *Report) LineV(x float64, y1 float64, y2 float64)

func (*Report) LoadCellsFromText

func (report *Report) LoadCellsFromText(filepath string) error

LoadCellsFromText, generate PDF file from cells file

func (*Report) MeasureTextWidth

func (report *Report) MeasureTextWidth(text string) float64

计算文本宽度, 必须先调用 SetFontWithStyle() 或者 SetFont()

func (*Report) NoCompression

func (report *Report) NoCompression()

func (*Report) Oval

func (report *Report) Oval(x1 float64, y1 float64, x2 float64, y2 float64)

func (*Report) Rect

func (report *Report) Rect(x1 float64, y1 float64, x2 float64, y2 float64)

画特定的图形, 目前支持: 长方形, 椭圆两大类

func (*Report) RegisterExecutor

func (report *Report) RegisterExecutor(execuror Executor, name string)

func (*Report) SaveAtomicCellText

func (report *Report) SaveAtomicCellText(filepath string)

保存原子操作单元

func (*Report) SetFont

func (report *Report) SetFont(family string, size int)

func (*Report) SetFontWithStyle

func (report *Report) SetFontWithStyle(family, style string, size int)

设置当前文本字体, 先注册,后设置

func (*Report) SetFonts

func (report *Report) SetFonts(fmap []*FontMap)

设置可用字体

func (*Report) SetMargin

func (report *Report) SetMargin(dx, dy float64)

func (*Report) SetPage

func (report *Report) SetPage(size string, orientation string)

设置页面的尺寸, unit: mm pt in size: A4 LTR, 目前支持常用的两种方式

func (*Report) SetXY

func (report *Report) SetXY(currX, currY float64)

currX, currY, 坐标

func (*Report) TextColor

func (report *Report) TextColor(red int, green int, blue int)

func (*Report) TextDefaultColor

func (report *Report) TextDefaultColor()

设置当前的字体颜色, 线条颜色

func (*Report) Var

func (report *Report) Var(name string, val string)

添加变量

type Scope

type Scope struct {
	Left   float64
	Top    float64
	Right  float64
	Bottom float64
}

When used as Margin, Right cannot take effect When used as a Border, Bottom cannot take effect

func NewScope

func NewScope(left, top, right, bottom float64) Scope

func (*Scope) ReplaceBorder

func (scope *Scope) ReplaceBorder()

func (*Scope) ReplaceMarign

func (scope *Scope) ReplaceMarign()

Jump to

Keyboard shortcuts

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