pdfHelper

package
v1.5.49 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// helper.FontOption.FontName             = "MyFont"
	PortraitValidWidth   = 190.0
	PortraitValidHeight  = 277.0
	LandscapeValidWidth  = 277.0
	LandscapeValidHeight = 190.0
	Margin               = 10

	HalfPortraitValidWidth = 95.0

	SignSpaceRowAmount      = 4    // 签字区域的空白行数
	SignerInfoRowAmount     = 8    // 签名人员信息高度(公司8 个人4)
	BlankRowHeight          = 8    // 签字区域单行高度
	SignFormPartyLineHeight = 10.0 // 签字区域 甲方乙方的行高
)
View Source
const FontBold = "B"
View Source
const FontHeavy = "H"
View Source
const FontLight = "L"
View Source
const FontRegular = ""

Variables

This section is empty.

Functions

This section is empty.

Types

type CompanySigner

type CompanySigner struct {
	OgName        string //【单位】单位名称
	OgLicenseNo   string //【单位】营业执照编号
	OgBankName    string //【单位】开户行名称
	OgBankNo      string //【单位】行号
	OgBankAccount string //【单位】银行账号
	OgTel         string //【单位】电话
	OgFax         string //【单位】传真
	OgAddress     string //【单位】地址
	LawPersonName string //【单位】法人姓名

	SignerName  string // 签署人真实姓名
	SignerPhone string // 签署人手机号

	SignData SignData // 签名信息
}

CompanySigner 公司签署

func (CompanySigner) GetHintName

func (signer CompanySigner) GetHintName() string

func (CompanySigner) GetKind

func (signer CompanySigner) GetKind() SignKind

func (CompanySigner) GetSignData

func (signer CompanySigner) GetSignData() SignData

type ContentStyle

type ContentStyle struct {
	LineHeight float64    // 行高
	DoIntent   bool       // 是否进行首行缩进两格
	TextAlign  string     // 水平对齐方式  gofpdf.AlignCenter 等
	FontWeight FontWeight // 文字粗细
	FontSize   float64    // 字体大小
	Color      *RGBColor  // 文字颜色
	BgColor    *RGBColor  // 背景色
}

type FontOption

type FontOption struct {
	LightTTFURL   string // 细体字体文件
	RegularTTFURL string // 常规体字体文件
	BoldTTFURL    string // 粗体字体文件
	HeavyTTFURL   string // 超粗体字体文件

	FontName string // 预设文本(预设字体名字如Arial,自定义的话随便取个名字)
}

type FontWeight

type FontWeight string

type FooterOption

type FooterOption struct {
	LeftText  string // 左侧文字
	RightText string // 右侧文字
}

type HeaderOption

type HeaderOption struct {
	LeftImgURL string // 左侧Logo地址
	RightText  string // 右侧文字(一般是文件编号)
}

type HeaderSlice

type HeaderSlice struct {
	Label string
	Width float64
}

type Ln

type Ln int
const Below Ln = 2
const ToTheRight Ln = 0
const Wrap Ln = 1

type PDFHelper

type PDFHelper struct {
	PDF             *gofpdf.Fpdf
	FontOption      *FontOption      // 字体设置
	HeaderOption    *HeaderOption    // 页眉设置
	FooterOption    *FooterOption    // 页脚设置
	WaterMarkOption *WaterMarkOption // 水印设置
}

func NewPDFHelper

func NewPDFHelper(fontOption *FontOption, headerOption *HeaderOption, footerOption *FooterOption, waterMarkOption *WaterMarkOption) (helper *PDFHelper)

NewPDFHelper 创建一个pdf助手

func (*PDFHelper) AddFooter

func (helper *PDFHelper) AddFooter()

AddFooter 添加页脚(两端文字,中间页码)

func (*PDFHelper) AddHeader

func (helper *PDFHelper) AddHeader()

AddHeader 添加页眉(左边logo,右边文件编号)

func (*PDFHelper) AddSignForm

func (helper *PDFHelper) AddSignForm(firstParty, secondParty SignerInterface, fillTime, fillIP bool) (err error)

AddSignForm 添加一个签字用的区域(如果带有签名数据也会一起渲染上去) 图片是网络地址的话,会先下载到当前项目根目录的/tmp下,注意权限

func (*PDFHelper) AddTableBody

func (helper *PDFHelper) AddTableBody(width float64, ln Ln, content string, opt ...*ContentStyle)

AddTableBody 添加一个表格体

func (*PDFHelper) AddTableBodyMulti

func (helper *PDFHelper) AddTableBodyMulti(width float64, startPoint *imgHelper.Position, content string, opt ...*ContentStyle) (thisLineEndPoint, nextLineStartPoint *imgHelper.Position)

AddTableBodyMulti 添加一个表格体

func (*PDFHelper) AddTableBodyMultiLines

func (helper *PDFHelper) AddTableBodyMultiLines(width float64, ln Ln, contentByte [][]byte, opt ...*ContentStyle) (countLine int)

AddTableBodyMultiLines 添加一个表格体(允许换行) 记得归位

func (*PDFHelper) AddTableBodyRow

func (helper *PDFHelper) AddTableBodyRow(widthSlice []float64, contentSlice []string, opt ...*ContentStyle)

AddTableBodyRow 新的tableBody写法(支持换行)

func (*PDFHelper) AddTableHead

func (helper *PDFHelper) AddTableHead(width float64, ln Ln, content string, opt ...*ContentStyle)

AddTableHead 添加一个表格头

func (*PDFHelper) AddTableHeadMulti

func (helper *PDFHelper) AddTableHeadMulti(width float64, startPoint *imgHelper.Position, content string, opt ...*ContentStyle) (thisLineEndPoint, nextLineStartPoint *imgHelper.Position)

AddTableHeadMulti 添加一个表格头

func (*PDFHelper) AddWaterMark

func (helper *PDFHelper) AddWaterMark()

AddWaterMark 添加水印(两种文字交替)

func (*PDFHelper) BatchSplitLines

func (helper *PDFHelper) BatchSplitLines(widthSlice []float64, contentSlice []string) (lineSlice [][]string, maxLines int, err error)

BatchSplitLines 批量拆分

func (*PDFHelper) FirstTitle

func (helper *PDFHelper) FirstTitle(text string)

FirstTitle 一级标题

func (*PDFHelper) GetTotalHeight

func (helper *PDFHelper) GetTotalHeight(content string, width float64, weight FontWeight, fontSize, lineHeight float64) (totalHeight float64)

GetTotalHeight 获取多行文字的行高

func (*PDFHelper) MainTitle

func (helper *PDFHelper) MainTitle(text string)

MainTitle 设置主标题

func (*PDFHelper) NormalContent

func (helper *PDFHelper) NormalContent(text string, opt ...*ContentStyle)

NormalContent 常规正文内容(前面会有两格缩进)

func (*PDFHelper) SaveAsImgs

func (helper *PDFHelper) SaveAsImgs(dir, fileName string) (localFilePaths []string, err error)

SaveAsImgs 以图片格式保存 dir : 要以斜杠 / 结尾 fileName : 不要后缀名

func (*PDFHelper) SaveAsPDF

func (helper *PDFHelper) SaveAsPDF(dir, fileName string) (filePath string, err error)

SaveAsPDF 保存为pdf dir : 要以斜杠 / 结尾 fileName : 不要后缀名

func (*PDFHelper) SecondTitle

func (helper *PDFHelper) SecondTitle(text string)

SecondTitle 二级标题

func (*PDFHelper) SplitLines

func (helper *PDFHelper) SplitLines(width float64, content string) (lines [][]byte, err error)

SplitLines 将文字拆分成几行

func (*PDFHelper) SplitText

func (helper *PDFHelper) SplitText(width float64, content string) (lines []string)

SplitText 将文字拆分成几行(UTF-8用这个)

type PersonSigner

type PersonSigner struct {
	TrueName string // 个人真实姓名
	Address  string // 地址
	Phone    string // 手机号
	IDCardNo string // 身份证号

	SignData SignData // 签名信息
}

PersonSigner 个人签署

func (PersonSigner) GetHintName

func (signer PersonSigner) GetHintName() string

func (PersonSigner) GetKind

func (signer PersonSigner) GetKind() SignKind

func (PersonSigner) GetSignData

func (signer PersonSigner) GetSignData() SignData

type RGBColor

type RGBColor struct {
	R int
	G int
	B int
}

RGBColor 文字等颜色

type RectArea

type RectArea struct {
	LeftTop     imgHelper.Position
	RightTop    imgHelper.Position
	LeftBottom  imgHelper.Position
	RightBottom imgHelper.Position
}

type SignData

type SignData struct {
	DoHint            bool // 是否提示签名区域高亮
	AutoSign          bool // 自动签名
	StampImg          *SignImg
	NameImg           *SignImg
	OverflowRate      float64 // 签名浮动区域(仅自动签名有效 0 - 1)
	PageNo            int     // 签署在合同的第几页
	Time              string  // 签署日期
	IP                string  // 签署IP
	SignFormCellStyle [SignSpaceRowAmount]*SignFormCellStyle

	FaceImg  *SignImg // 人脸识别照片(目前不做相关处理)
	SignerID uint64   // 签署人主体ID(目前不做相关处理)
}

type SignFormCellStyle

type SignFormCellStyle struct {
	Content string
	Fill    bool
}

type SignImg

type SignImg struct {
	URL      string              // 图片地址
	Position *imgHelper.Position // 中心点
	Size     *imgHelper.Size     // 尺寸
}

type SignKind

type SignKind int8
const Company SignKind = 2 // 单位
const Person SignKind = 1 // 个人

type SignerInterface

type SignerInterface interface {
	GetKind() SignKind
	GetSignData() SignData
	GetHintName() string // 提示签字的姓名
}

type WaterMarkOption

type WaterMarkOption struct {
	TextCn   string    // 水印文字(中文)
	TextEn   string    // 水印文字(英文)
	FontSize float64   // 字体大小
	Color    *RGBColor // 颜色
}

WaterMarkOption 水印设置

Jump to

Keyboard shortcuts

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