Cgopdf

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 23 Imported by: 0

README

gopdf

GitHub GitHub GitHub GitHub issues GitHub code size in bytes

项目介绍

本项目是https://github.com/tiechui1994/gopdf的二次开发版

gopdf 是一个生成 PDF 文档的 Golang 库. 主要有以下的特点:

  • 支持 Unicode 字符 (包括中文, 日语, 朝鲜语, 等等.)
  • 文档内容的自动定位与分页, 减少用户的工作量.
  • 支持图片插入, 支持多种图片格式, PNG, BMP, JPEG, WEBP, TIFF
  • 支持文档压缩
  • 复杂表格组件, 块文本等
  • markdown 文本可以直接转换成 pdf
  • 手动实现了 markdown 解析库, 可以提供其他 markdown 开发

安装

go get -u gitee.com/cindoralla/gopdf

案例展示:

image

代码参考 example/complex_report_test

image

代码参考 example/simple_table_test

image

代码参考 example/mutil_table_test

未来开发计划

  1. 准备尝试开发 Markdown 的语法解析库, 然后通过解析库将 markdown 转换成 pdf, 可以支持定义一些颜色风格. 目前正 在研究 marked.js 前段库, 寻找灵感.

  2. 优化 Markedown 的解析库, 调整 markdown 转 pdf 的参数, 使得 pdf 页面更美观.

  3. 开发更加通俗易用的组件, 比如 paragraph, tablecell 等.

Documentation

Index

Constants

View Source
const (
	DIV_STRAIGHT = 1 // 实线边框
	DIV_DASHED   = 2 // 虚线边框
	DIV_DOTTED   = 3 // 点状线的边框
	DIV_NONE     = 4 // 无边框
)
View Source
const (
	FONT_NORMAL = "normal"
	FONT_BOLD   = "bold"
	FONT_IALIC  = "italic"
)
View Source
const (
	TYPE_TEXT     = "text"
	TYPE_STRONG   = "strong"   // **strong**
	TYPE_EM       = "em"       // *em*
	TYPE_CODESPAN = "codespan" // `codespan`, “`codespan“`
	TYPE_CODE     = "code"     //
	TYPE_LINK     = "link"     // [xx](http://www.link)
	TYPE_IMAGE    = "image"    // ![xxx](https://www.image)

	TYPE_SPACE = "space"

	TYPE_PARAGRAPH  = "paragraph"
	TYPE_HEADING    = "heading"
	TYPE_LIST       = "list"
	TYPE_BLOCKQUOTE = "blockquote"
)
View Source
const (
	PNG  = "png"
	BMP  = "bmp"
	WEBP = "webp"
	TIFF = "tiff"
	JPEG = "jpeg"
)

Variables

This section is empty.

Functions

func CommonGenerateAtomicCell

func CommonGenerateAtomicCell(children *[]mardown) (pagebreak, over bool, err error)

func Convert2JPEG

func Convert2JPEG(srcPath string, dstPath string) error

func ConvertBMP2JPEG

func ConvertBMP2JPEG(srcPath, dstPath string) (err error)

func ConvertPNG2JPEG

func ConvertPNG2JPEG(srcPath, dstPath string) (err error)

func ConvertTIFF2JPEG

func ConvertTIFF2JPEG(srcPath, dstPath string) (err error)

func ConvertWEBP2JPEG

func ConvertWEBP2JPEG(srcPath, dstPath string) (err error)

func DrawFiveCycle

func DrawFiveCycle(srcPath string)

func DrawInnerFiveCycle

func DrawInnerFiveCycle(srcPath string)

func DrawPNG

func DrawPNG(srcPath string)

func DrawPlumCurve

func DrawPlumCurve(srcPath string)

func DrawRotationOutCircle

func DrawRotationOutCircle(srcPath string)

func DrawSunLine

func DrawSunLine(srcPath string)

func GetImageWidthAndHeight

func GetImageWidthAndHeight(picturePath string) (w, h int)

Types

type Div

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

带有各种边框的内容, 可以自动换行

func NewDiv

func NewDiv(lineHeight, lineSpce float64, pdf *core.Report) *Div

func NewDivWithWidth

func NewDivWithWidth(width float64, lineHeight, lineSpce float64, pdf *core.Report) *Div

func (*Div) Copy

func (div *Div) Copy(content string) *Div

func (*Div) GenerateAtomicCell

func (div *Div) GenerateAtomicCell() error

自动分页

func (*Div) GetHeight

func (div *Div) GetHeight() (height float64)

func (*Div) GetWidth

func (div *Div) GetWidth() (width float64)

func (*Div) HorizontalCentered

func (div *Div) HorizontalCentered() *Div

func (*Div) RightAlign

func (div *Div) RightAlign() *Div

func (*Div) SetBackColor

func (div *Div) SetBackColor(color string) *Div

func (*Div) SetBorder

func (div *Div) SetBorder(border core.Scope) *Div

func (*Div) SetContent

func (div *Div) SetContent(content string) *Div

func (*Div) SetFont

func (div *Div) SetFont(font core.Font) *Div

func (*Div) SetFontColor

func (div *Div) SetFontColor(color string) *Div

func (*Div) SetFontWithColor

func (div *Div) SetFontWithColor(font core.Font, color string) *Div

func (*Div) SetFrameType

func (div *Div) SetFrameType(frameType int) *Div

func (*Div) SetMarign

func (div *Div) SetMarign(margin core.Scope) *Div

type HLine

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

func NewHLine

func NewHLine(pdf *core.Report) *HLine

func (*HLine) GenerateAtomicCell

func (h *HLine) GenerateAtomicCell()

func (*HLine) SetColor

func (h *HLine) SetColor(color float64) *HLine

func (*HLine) SetMargin

func (h *HLine) SetMargin(margin core.Scope) *HLine

func (*HLine) SetWidth

func (h *HLine) SetWidth(width float64) *HLine

type Image

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

func NewImage

func NewImage(path string, pdf *core.Report) *Image

func NewImageWithWidthAndHeight

func NewImageWithWidthAndHeight(path string, width, height float64, pdf *core.Report) *Image

func (*Image) GenerateAtomicCell

func (image *Image) GenerateAtomicCell() (pagebreak, over bool, err error)

×Ô¶¯»»ÐÐ

func (*Image) GetHeight

func (image *Image) GetHeight() float64

func (*Image) GetWidth

func (image *Image) GetWidth() float64

func (*Image) SetAutoBreak

func (image *Image) SetAutoBreak()

func (*Image) SetMargin

func (image *Image) SetMargin(margin core.Scope) *Image

type MarkdownText

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

func NewMarkdownText

func NewMarkdownText(pdf *core.Report, x float64, fonts map[string]string) (*MarkdownText, error)

func (*MarkdownText) GenerateAtomicCell

func (mt *MarkdownText) GenerateAtomicCell() (err error)

func (*MarkdownText) SetTokens

func (mt *MarkdownText) SetTokens(tokens []Token)

type MdBlockQuote

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

func (*MdBlockQuote) GenerateAtomicCell

func (a *MdBlockQuote) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdBlockQuote) GetType

func (a *MdBlockQuote) GetType() string

func (*MdBlockQuote) SetText

func (a *MdBlockQuote) SetText(interface{}, ...string)

func (*MdBlockQuote) SetToken

func (b *MdBlockQuote) SetToken(t Token) error

type MdHeader

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

func (*MdHeader) CalFontSizeAndLineHeight

func (h *MdHeader) CalFontSizeAndLineHeight(size int) (fontsize int, lineheight float64)

func (*MdHeader) GenerateAtomicCell

func (h *MdHeader) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdHeader) GetType

func (a *MdHeader) GetType() string

func (*MdHeader) SetText

func (a *MdHeader) SetText(interface{}, ...string)

func (*MdHeader) SetToken

func (h *MdHeader) SetToken(t Token) (err error)

type MdImage

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

func (*MdImage) GenerateAtomicCell

func (i *MdImage) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdImage) GetType

func (i *MdImage) GetType() string

func (*MdImage) SetText

func (i *MdImage) SetText(_ interface{}, filename ...string)

type MdList

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

func (*MdList) GenerateAtomicCell

func (l *MdList) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdList) GetType

func (a *MdList) GetType() string

func (*MdList) SetText

func (a *MdList) SetText(interface{}, ...string)

func (*MdList) SetToken

func (l *MdList) SetToken(t Token) error

func (*MdList) String

func (l *MdList) String() string

type MdMutiText

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

func (*MdMutiText) GenerateAtomicCell

func (a *MdMutiText) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdMutiText) GetType

func (a *MdMutiText) GetType() string

func (*MdMutiText) SetText

func (a *MdMutiText) SetText(interface{}, ...string)

func (*MdMutiText) SetToken

func (m *MdMutiText) SetToken(t Token) error

type MdParagraph

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

func (*MdParagraph) GenerateAtomicCell

func (p *MdParagraph) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdParagraph) GetType

func (a *MdParagraph) GetType() string

func (*MdParagraph) SetText

func (a *MdParagraph) SetText(interface{}, ...string)

func (*MdParagraph) SetToken

func (p *MdParagraph) SetToken(t Token) error

type MdSpace

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

func (*MdSpace) GenerateAtomicCell

func (c *MdSpace) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdSpace) GetType

func (a *MdSpace) GetType() string

func (*MdSpace) SetText

func (a *MdSpace) SetText(interface{}, ...string)

func (*MdSpace) String

func (c *MdSpace) String() string

type MdText

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

Atomic component

func (*MdText) GenerateAtomicCell

func (c *MdText) GenerateAtomicCell() (pagebreak, over bool, err error)

func (*MdText) GetSubText

func (c *MdText) GetSubText(x1, x2 float64) (text string, width float64, newline bool)

GetSubText, Returns the content of a string of length x2-x1. This string is a substring of text. After return, the remain and length will change

func (*MdText) GetType

func (a *MdText) GetType() string

func (*MdText) SetText

func (c *MdText) SetText(font interface{}, texts ...string)

func (*MdText) String

func (c *MdText) String() string

type Span

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

不会进行自动分页, 可以用于页眉, 页脚的内容.

func NewSpan

func NewSpan(lineHeight, lineSpce float64, pdf *core.Report) *Span

func NewSpanWithWidth

func NewSpanWithWidth(width float64, lineHeight, lineSpce float64, pdf *core.Report) *Span

func (*Span) Copy

func (span *Span) Copy(content string) *Span

func (*Span) GenerateAtomicCell

func (span *Span) GenerateAtomicCell() error

func (*Span) GetHeight

func (span *Span) GetHeight() (height float64)

func (*Span) GetWidth

func (span *Span) GetWidth() (width float64)

func (*Span) HorizontalCentered

func (span *Span) HorizontalCentered() *Span

func (*Span) RightAlign

func (span *Span) RightAlign() *Span

func (*Span) SetBorder

func (span *Span) SetBorder(border core.Scope) *Span

func (*Span) SetContent

func (span *Span) SetContent(content string) *Span

func (*Span) SetFont

func (span *Span) SetFont(font core.Font) *Span

func (*Span) SetFontColor

func (span *Span) SetFontColor(color string) *Span

func (*Span) SetFontWithColor

func (span *Span) SetFontWithColor(font core.Font, color string) *Span

func (*Span) SetHeight

func (span *Span) SetHeight(height float64) *Span

func (*Span) SetMarign

func (span *Span) SetMarign(margin core.Scope) *Span

func (*Span) VerticalCentered

func (span *Span) VerticalCentered() *Span

type Table

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

构建表格

func NewTable

func NewTable(cols, rows int, width, lineHeight float64, pdf *core.Report) *Table

func (*Table) GenerateAtomicCell

func (table *Table) GenerateAtomicCell() error

func (*Table) GetColWidth

func (table *Table) GetColWidth(row, col int) float64

获取某列的宽度

func (*Table) NewCell

func (table *Table) NewCell() *TableCell

创建长宽为1的单元格

func (*Table) NewCellByRange

func (table *Table) NewCellByRange(w, h int) *TableCell

创建固定长度的单元格

func (*Table) SetLineHeight

func (table *Table) SetLineHeight(lineHeight float64)

设置表的行高, 行高必须大于当前使用字体的行高

func (*Table) SetMargin

func (table *Table) SetMargin(margin core.Scope)

设置表的外

type TableCell

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

func (*TableCell) SetElement

func (cell *TableCell) SetElement(e core.Cell) *TableCell

type TextCell

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

func NewTextCell

func NewTextCell(width, lineHeight, lineSpace float64, pdf *core.Report) *TextCell

func (*TextCell) Copy

func (cell *TextCell) Copy(content string) *TextCell

func (*TextCell) GenerateAtomicCell

func (cell *TextCell) GenerateAtomicCell(maxheight float64) (int, int, error)

先涂背景颜色, 然后在背景颜色的基础上写入内容

func (*TextCell) GetHeight

func (cell *TextCell) GetHeight() float64

func (*TextCell) GetLastHeight

func (cell *TextCell) GetLastHeight() float64

func (*TextCell) HorizontalCentered

func (cell *TextCell) HorizontalCentered() *TextCell

func (*TextCell) RightAlign

func (cell *TextCell) RightAlign() *TextCell

func (*TextCell) SetBackColor

func (cell *TextCell) SetBackColor(color string) *TextCell

func (*TextCell) SetBorder

func (cell *TextCell) SetBorder(border core.Scope) *TextCell

func (*TextCell) SetContent

func (cell *TextCell) SetContent(s string) *TextCell

func (*TextCell) SetFont

func (cell *TextCell) SetFont(font core.Font) *TextCell

func (*TextCell) SetFontColor

func (cell *TextCell) SetFontColor(color string) *TextCell

func (*TextCell) SetFontWithColor

func (cell *TextCell) SetFontWithColor(font core.Font, color string) *TextCell

func (*TextCell) TryGenerateAtomicCell

func (cell *TextCell) TryGenerateAtomicCell(maxheight float64) (int, int)

func (*TextCell) VerticalCentered

func (cell *TextCell) VerticalCentered() *TextCell

type Token

type Token = lex.Token

Token is parse markdown result element

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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