pdfext

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

pdfext

extension of gopdf(github.com/signintech/gopdf) for form/table

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawRectCell

func DrawRectCell(pdf *gopdf.GoPdf,
	text string,
	fontSize int,
	x, y, w, h float64,
	color Color,
	align Halign, valign Valign,
)

//////////////////////////////////////////////////

func DrawRectMultiCell

func DrawRectMultiCell(pdf *gopdf.GoPdf,
	text string,
	fontSize int,
	x, y, w, h float64,
	rowheight float64,
	color Color,
	align Halign, valign Valign,
)

func ToTableData

func ToTableData(data interface{}) []map[string]string

Types

type CellStyle

type CellStyle struct {
	Background Color
	Font       string
	FontColor  Color
	FontSize   int
	H_Align    Halign
	V_Align    Valign
}

格子样式

type Color

type Color int32
const (
	Black     Color = 1
	White     Color = 2
	Gray      Color = 3
	Red       Color = 4
	Green     Color = 5
	Yellow    Color = 6
	Blue      Color = 7
	LightGray Color = 31
)

颜色

type Column

type Column struct {
	//Size       int
	Width       float64 // 宽度
	AutoFit     bool    // 自适应,未生效
	ColumnSytle CellStyle
	Name        string // 列名
}

type FontStyle

type FontStyle struct {
	FontSize  int    // 字体大小
	FontName  string // 字体名称, 使用AddFonts注册字体时的名称
	FontColor Color
}

type Form

type Form struct {
	Name      string     // 表单名称, 空则不显示名称
	NameStyle FontStyle  // 名称字体样式
	ColNum    int        //表单列数, Name+Value为一列
	Units     []FormUnit // Name+Value为Unit
	MaxWidth  float64    // 表单最大宽度
	Unitstyle UnitStyle  // Unit的样式
	YPosition float64    // 起始Y坐标
	RowHeight float64    // 每行高度
}

func NewForm

func NewForm() *Form

func (*Form) Draw

func (f *Form) Draw(p *Pdf)

type FormUnit

type FormUnit struct {
	UnitName  string
	UnitValue string
}

type Halign

type Halign int32
const (
	HalignLeft   Halign = 1
	HalignCenter Halign = 2
	HalignRight  Halign = 3
)

文本水平样式

type Header struct {
	LeftText    string
	CenterText  string
	RightText   string
	HeaderStyle FontStyle
}

func NewHeader

func NewHeader() *Header

func (*Header) Draw

func (h *Header) Draw(p *Pdf)

type Pdf

type Pdf struct {
	FileName string //文件名

	Fonts       []string   //已注册字体
	CurrentFont *FontStyle // 当前字体
	CurrentXY   XY         //当前位置
	MaxWidth    float64    // 内容区域最大宽度
	MaxHeight   float64    // 内容区域最大高度
	// contains filtered or unexported fields
}

pdf

func NewPdf

func NewPdf(filename string) *Pdf

func (*Pdf) AddFont

func (p *Pdf) AddFont(fontname, fontpath string) error

注册字体

func (*Pdf) AddFonts

func (p *Pdf) AddFonts(fonts map[string]string) error

注册字体

func (*Pdf) AddForm

func (p *Pdf) AddForm(form *Form) error

func (*Pdf) AddHeader

func (p *Pdf) AddHeader(header *Header) error

func (*Pdf) AddPage added in v0.1.1

func (p *Pdf) AddPage()

func (*Pdf) AddTable

func (p *Pdf) AddTable(table *Table) error

func (*Pdf) AddText

func (p *Pdf) AddText(text *Text) error

func (*Pdf) Save

func (p *Pdf) Save() error

func (*Pdf) SetFont

func (p *Pdf) SetFont(style *FontStyle) *gopdf.GoPdf

func (*Pdf) UpdateXY added in v0.1.1

func (p *Pdf) UpdateXY(xy XY) XY

type Table

type Table struct {
	Name             string                // 表格名字,为空不显示
	NameStyle        FontStyle             // 名字样式
	Colums           []Column              // 列
	Width            float64               // 表格宽度
	Data             []map[string]string   // 数据, 可通过ToTableData()转换
	YPosition        float64               // 起始Y坐标
	RowHeight        float64               // 行高
	TitleStyle       CellStyle             // 表头样式
	DataStyle        CellStyle             // 表格数据样式
	ColumnDataStyles map[string]*CellStyle // 特定列数据样式, font, fontsize, fontcolor不生效
}

表格

func NewTable

func NewTable() *Table

func (*Table) Draw

func (t *Table) Draw(p *Pdf)

type Text

type Text struct {
	Content string // 文本内容
	//MaxWidth  float64   // 文本最大宽度
	TextStyle CellStyle // 文本样式
	YPosition float64   // Y坐标
}

文本

func NewText

func NewText() *Text

func (*Text) Draw

func (t *Text) Draw(p *Pdf)

type UnitStyle

type UnitStyle struct {
	NameWidth  float64   // Name单元格的宽度
	ValueWidth float64   // Value单元格的宽度
	AutoFit    bool      // 自适应, 不生效
	NameStyle  CellStyle // Name单元格的样式
	ValueStyle CellStyle // Value单元格的样式
}

表单

type Valign

type Valign int32
const (
	ValignTop    Valign = 1
	ValignMiddle Valign = 2
	ValignBottom Valign = 3
)

文本垂直样式

type XY

type XY struct {
	X float64
	Y float64
}

x,y坐标

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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