gopdf

package module
v0.0.0-...-31a8737 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 7 Imported by: 0

README

gopdf

Documentation

Index

Constants

View Source
const (
	AlignLeft   = "L"
	AlignCenter = "C"
	AlignRight  = "R"
)
View Source
const (
	AlignTop      = "T"
	AlignMiddle   = "M"
	AlignBottom   = "B"
	AlignBaseline = "A"
)
View Source
const (
	FontFamilyCourier    = "Courier"
	FontFamilyHelvetica  = "Helvetica"
	FontFamilyTimes      = "Times"
	FontFamilySymbol     = "Symbol"
	FontFamilyNotoSansTC = "NotoSansTC"
	FontFamilyNotoSansSC = "NotoSansSC"
)
View Source
const (
	PaperA3      = "A3"
	PaperA4      = "A4"
	PaperA5      = "A5"
	PaperLetter  = "Letter"
	PaperLegal   = "Legal"
	PaperTabloid = "Tabloid"
)

Variables

View Source
var (
	OrientationPortrait  = "P"
	OrientationLandscape = "L"
)

Functions

This section is empty.

Types

type BorderStyle

type BorderStyle struct {
	Top    bool `json:"top"`
	Left   bool `json:"left"`
	Right  bool `json:"right"`
	Bottom bool `json:"bottom"`
	Color  *RGB `json:"color"`
}

func NewBorderStyle

func NewBorderStyle(top, left, right, bottom bool, color *RGB) *BorderStyle

func (*BorderStyle) BorderToEngineString

func (s *BorderStyle) BorderToEngineString() string

func (*BorderStyle) SetupBorderColor

func (s *BorderStyle) SetupBorderColor(p *PDF)

type Cell

type Cell struct {
	Text         string     `json:"text"`
	Style        *CellStyle `json:"style"`
	Width        float64    `json:"width"`
	WidthPercent float64    `json:"width_percent"`
}

func NewCell

func NewCell(text string, style *CellStyle, width float64, widthPercentage float64) *Cell

func (*Cell) SetStyle

func (c *Cell) SetStyle(style *CellStyle)

type CellStyle

type CellStyle struct {
	FontStyle   *FontStyle   `json:"font_style"`
	BorderStyle *BorderStyle `json:"border_style"`
	FillColor   *RGB         `json:"fill_color"`
	HAlign      string       `json:"h_align"`
	VAlign      string       `json:"v_align"`
}

func NewCellStyle

func NewCellStyle(fontStyle *FontStyle, borderStyle *BorderStyle, fillColor *RGB, hAlign, vAlign string) *CellStyle

func (*CellStyle) HAlignToEngineString

func (s *CellStyle) HAlignToEngineString() string

func (*CellStyle) SetBorderStyle

func (s *CellStyle) SetBorderStyle(style *BorderStyle)

func (*CellStyle) SetFillColor

func (s *CellStyle) SetFillColor(color *RGB)

func (*CellStyle) SetFontStyle

func (s *CellStyle) SetFontStyle(style *FontStyle)

func (*CellStyle) SetHAlign

func (s *CellStyle) SetHAlign(align string)

func (*CellStyle) SetVAlign

func (s *CellStyle) SetVAlign(align string)

func (*CellStyle) SetupFillColor

func (s *CellStyle) SetupFillColor(p *PDF)

func (*CellStyle) ToAlignEngineString

func (s *CellStyle) ToAlignEngineString() string

func (*CellStyle) VAlignToEngineString

func (s *CellStyle) VAlignToEngineString() string

type FontStyle

type FontStyle struct {
	FontFamily string  `json:"font_family"`
	FontSize   float64 `json:"font_size"`
	LineHeight float64 `json:"line_height"`
	FontColor  *RGB    `json:"font_color"`
	Bold       bool    `json:"bold"`
	Strikeout  bool    `json:"strikeout"`
	Underline  bool    `json:"underline"`
}

func NewFontStyle

func NewFontStyle(
	fontFamily string,
	fontSize float64,
	lineHeight float64,
	fontColor *RGB,
	bold, strikeout, underline bool,
) *FontStyle

func (*FontStyle) SetBold

func (s *FontStyle) SetBold(bold bool)

SetBold sets the font style to bold. By default, the font style is not bold.

func (*FontStyle) SetFontColor

func (s *FontStyle) SetFontColor(fontColor *RGB)

SetFontColor sets the font color for the PDF. By default, the font color is black.

func (*FontStyle) SetFontFamily

func (s *FontStyle) SetFontFamily(fontFamily string)

SetFontFamily sets the font family for the PDF. By default, the font family is Helvetica.

func (*FontStyle) SetFontSize

func (s *FontStyle) SetFontSize(fontSize float64)

SetFontSize sets the font size for the PDF. By default, the font size is 12.

func (*FontStyle) SetLineHeight

func (s *FontStyle) SetLineHeight(lineHeight float64)

SetLineHeight sets the line height for the PDF. By default, the line height same as the font size.

func (*FontStyle) SetStrikeout

func (s *FontStyle) SetStrikeout(strikeout bool)

SetStrikeout sets the font style to strikeout. By default, the font style is not strikeout.

func (*FontStyle) SetUnderline

func (s *FontStyle) SetUnderline(underline bool)

SetUnderline sets the font style to underline. By default, the font style is not underline.

func (*FontStyle) Setup

func (s *FontStyle) Setup(pdf *PDF)

Setup sets the font style for the PDF.

type PDF

type PDF struct {
	Engine           *gofpdf.Fpdf `json:"-"`
	PageLayout       *PageLayout  `json:"page_layout"`
	DefaultFontStyle *FontStyle   `json:"default_font_style"`
	CurrentPageIndex int          `json:"-"`

	PageHeight       float64 `json:"page_height"`
	PageWidth        float64 `json:"page_width"`
	PageMarginTop    float64 `json:"page_margin_top"`
	PageMarginBottom float64 `json:"page_margin_bottom"`
	PageMarginLeft   float64 `json:"page_margin_left"`
	PageMarginRight  float64 `json:"page_margin_right"`
	PageBodyHeight   float64 `json:"page_body_height"` // Page height minus top and bottom margins
	PageBodyWidth    float64 `json:"page_body_width"`  // Page width minus left and right margins
}

func New

func New(layout ...*PageLayout) *PDF

func (*PDF) AddPage

func (p *PDF) AddPage()

func (*PDF) LineBreak

func (p *PDF) LineBreak(style *FontStyle)

func (*PDF) SetDefaultFontStyle

func (p *PDF) SetDefaultFontStyle(style *FontStyle)

func (*PDF) ToBytes

func (p *PDF) ToBytes() []byte

func (*PDF) ToFile

func (p *PDF) ToFile(filePath string)

func (*PDF) WriteImage

func (p *PDF) WriteImage(imgSrc string, width float64, height float64, flow bool)

func (*PDF) WriteImageBytes

func (p *PDF) WriteImageBytes(imgBytes []byte, width float64, height float64, flow bool)
func (p *PDF) WriteLink(text string, link string, style *FontStyle)

func (*PDF) WriteTable

func (p *PDF) WriteTable(cells []*Cell, padding *Padding)

func (*PDF) WriteText

func (p *PDF) WriteText(text string, style *FontStyle)

func (*PDF) WriteTextBox

func (p *PDF) WriteTextBox(text string, align string, style *FontStyle)

type Padding

type Padding struct {
	Top    float64 `json:"top"`
	Left   float64 `json:"left"`
	Right  float64 `json:"right"`
	Bottom float64 `json:"bottom"`
}

func NewPadding

func NewPadding(top, left, right, bottom float64) *Padding

type Page

type Page struct {
	PageLayout *PageLayout `json:"page_layout"`

	PageHeight       float64 `json:"page_height"`
	PageWidth        float64 `json:"page_width"`
	PageMarginTop    float64 `json:"page_margin_top"`
	PageMarginBottom float64 `json:"page_margin_bottom"`
	PageMarginLeft   float64 `json:"page_margin_left"`
	PageMarginRight  float64 `json:"page_margin_right"`
	PageBodyHeight   float64 `json:"page_body_height"`
	PageBodyWidth    float64 `json:"page_body_width"`
}

func NewPage

func NewPage(pdf *PDF) *Page

type PageLayout

type PageLayout struct {
	Orientation      string      `json:"orientation"`
	Paper            string      `json:"paper"`
	PageMargin       *PageMargin `json:"page_margin"`
	DefaultFontStyle *FontStyle  `json:"default_font_style"`
}

func NewPageLayout

func NewPageLayout(orientation, paper string) *PageLayout

func (*PageLayout) SetOrientation

func (s *PageLayout) SetOrientation(orientation string)

SetOrientation sets the orientation for the PDF. By default, the orientation is portrait.

func (*PageLayout) SetPaper

func (s *PageLayout) SetPaper(paper string)

SetPaper sets the paper size for the PDF. By default, the paper size is A4.

type PageMargin

type PageMargin struct {
	Top    float64 `json:"top"`
	Left   float64 `json:"left"`
	Right  float64 `json:"right"`
	Bottom float64 `json:"bottom"`
}

func NewPageMargin

func NewPageMargin(top, left, right, bottom float64) *PageMargin

type RGB

type RGB struct {
	R int `json:"r"`
	G int `json:"g"`
	B int `json:"b"`
}

func NewRGB

func NewRGB(r, g, b int) *RGB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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