pdf

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Maroto

type Maroto interface {
	// Grid System
	Row(height float64, closure func())
	Col(width uint, closure func())
	ColSpace(gridSize uint)

	// Registers
	RegisterHeader(closure func())
	RegisterFooter(closure func())

	// Outside Col/Row Components
	TableList(header []string, contents [][]string, prop ...props.TableList)
	Line(spaceHeight float64)

	// Inside Col/Row Components
	Text(text string, prop ...props.Text)
	FileImage(filePathName string, prop ...props.Rect) (err error)
	Base64Image(base64 string, extension consts.Extension, prop ...props.Rect) (err error)
	Barcode(code string, prop ...props.Barcode) error
	QrCode(code string, prop ...props.Rect)
	Signature(label string, prop ...props.Font)

	// File System
	OutputFileAndClose(filePathName string) error
	Output() (bytes.Buffer, error)

	// Helpers
	AddPage()
	SetBorder(on bool)
	SetBackgroundColor(color color.Color)
	SetAliasNbPages(alias string)
	SetFirstPageNb(number int)
	GetBorder() bool
	GetPageSize() (width float64, height float64)
	GetCurrentPage() int
	GetCurrentOffset() float64
	SetPageMargins(left, top, right float64)
	GetPageMargins() (left float64, top float64, right float64, bottom float64)
}

Maroto is the principal abstraction to create a PDF document.

func NewMaroto

func NewMaroto(orientation consts.Orientation, pageSize consts.PageSize) Maroto

NewMaroto create a Maroto instance returning a pointer to PdfMaroto Receive an Orientation and a PageSize. Shorthand when using a preset page size from consts.PageSize

Example

ExampleNewMaroto demonstrates how to create maroto

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Do things
	m.GetPageMargins()

	// Do more things and save...
}
Output:

func NewMarotoCustomSize

func NewMarotoCustomSize(orientation consts.Orientation, pageSize consts.PageSize, unitStr string, width, height float64) Maroto

NewMarotoCustomSize creates a Maroto instance returning a pointer to PdfMaroto Receive an Orientation and a PageSize. Use if custom page size is needed. Otherwise use NewMaroto() shorthand if using page sizes from consts.Pagesize. If using custom width and height, pageSize is just a string value for the format and takes no effect. Width and height inputs are measurements of the page in Portrait orientation.

Example

ExampleNewMaroto demonstrates how to create maroto with custom page size

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMarotoCustomSize(consts.Landscape, "C6", "mm", 114.0, 162.0)

	// Do things
	m.GetPageMargins()

	// Do more things and save...
}
Output:

type PdfMaroto

type PdfMaroto struct {
	Pdf             gofpdf.Pdf
	Math            internal.Math
	Font            internal.Font
	TextHelper      internal.Text
	SignHelper      internal.Signature
	Image           internal.Image
	Code            internal.Code
	TableListHelper internal.TableList
	// contains filtered or unexported fields
}

PdfMaroto is the principal structure which implements Maroto abstraction

func (*PdfMaroto) AddPage

func (s *PdfMaroto) AddPage()

AddPage adds a new page in the PDF

Example

ExamplePdfMaroto_AddPage how to force add a new page

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Add rows, cols and components
	m.AddPage()

	// Add rows, col and components in a new page
	// Do more things and save...
}
Output:

func (*PdfMaroto) Barcode

func (s *PdfMaroto) Barcode(code string, prop ...props.Barcode) (err error)

Barcode create an barcode inside a cell.

Example

ExamplePdfMaroto_Barcode demonstrates how to place a barcode inside a Col.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// Passing nil on barcode props parameter implies the Barcode fills it's
	// context cell depending on it's size.
	// It's possible to define the barcode positioning through
	// the top and left parameters unless center parameter is true.
	// In brief, when center parameter equals true, left and top parameters has no effect.
	// Percent parameter represents the Barcode's width/height inside the cell.
	// i.e. Percent: 75 means that the Barcode will take up 75% of Col's width
	// There is a constraint in the proportion defined, height cannot be greater than 20% of
	// the width, and height cannot be smaller than 10% of the width.

	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Do a lot of things on rows and columns...

	m.Col(12, func() {
		_ = m.Barcode("https://github.com/terinyo/maroto", props.Barcode{
			Percent:    75,
			Proportion: props.Proportion{Width: 50, Height: 10},
			Center:     true,
		})
	})

	// do more things...
}
Output:

func (*PdfMaroto) Base64Image

func (s *PdfMaroto) Base64Image(base64 string, extension consts.Extension, prop ...props.Rect) error

Base64Image add an Image reading byte slices inside a cell. Defining Image properties.

Example

ExamplePdfMaroto_Base64Image demonstrates how to add an Image from a base64 string.

package main

import (
	"encoding/base64"

	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// When props.Rect is nil, method make Image fulfill the context cell.
	// When center is true, left and top has no effect.
	// Percent represents the width/height of the Image inside the cell,
	// Ex: 85, means that Image will have width of 85% of column width.
	// When center is false, is possible to manually positioning the Image.

	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	// Bytes of the image loaded
	bytes := []byte{1, 2, 3}
	base64String := base64.StdEncoding.EncodeToString(bytes)

	m.Row(rowHeight, func() {
		m.Col(12, func() {
			_ = m.Base64Image(base64String, consts.Png, props.Rect{
				Left:    5,
				Top:     5,
				Center:  true,
				Percent: 85,
			})
		})
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) Col

func (s *PdfMaroto) Col(width uint, closure func())

Col create a column inside a row and enable to add components inside.

Example

ExamplePdfMaroto_Col demonstrates how to add an useful column

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	// Warning: The sum of all column gridSize cannot extrapolate 12
	m.Row(rowHeight, func() {
		m.Col(12, func() {
			// Add Image, Text, Signature, QrCode or Barcode...
		})
	})

	// Warning: The sum of all column gridSize cannot extrapolate 12
	m.Row(rowHeight, func() {
		m.Col(6, func() {
			// Add Image, Text, Signature, QrCode or Barcode...
		})
		m.Col(6, func() {
			// Add Image, Text, Signature, QrCode or Barcode...
		})
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) ColSpace

func (s *PdfMaroto) ColSpace(gridSize uint)

ColSpace create an empty column inside a row.

Example

ExamplePdfMaroto_ColSpace demonstrates how to add an empty column inside a row.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	// Warning: The sum of all column gridSize cannot extrapolate 12
	m.Row(rowHeight, func() {
		m.ColSpace(12)
	})

	// Warning: The sum of all column gridSize cannot extrapolate 12
	m.Row(rowHeight, func() {
		m.ColSpace(6)
		m.ColSpace(6)
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) FileImage

func (s *PdfMaroto) FileImage(filePathName string, prop ...props.Rect) error

FileImage add an Image reading from disk inside a cell. Defining Image properties.

Example

ExamplePdfMaroto_FileImage demonstrates how add an Image reading from disk.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// When props.Rect is nil, method make Image fulfill the context cell.
	// When center is true, left and top has no effect.
	// Percent represents the width/height of the Image inside the cell,
	// Ex: 85, means that Image will have width of 85% of column width.
	// When center is false, is possible to manually positioning the Image.

	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	m.Row(rowHeight, func() {
		m.Col(12, func() {
			_ = m.FileImage("path/Image.jpg", props.Rect{
				Left:    5,
				Top:     5,
				Center:  true,
				Percent: 85,
			})
		})
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) GetBorder

func (s *PdfMaroto) GetBorder() bool

GetBorder return the actual border value.

Example

ExamplePdfMaroto_GetBorder demonstrates how to obtain the actual borders status

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// false
	_ = m.GetBorder()

	m.SetBorder(true)

	// true
	_ = m.GetBorder()

	// Do more things and save...
}
Output:

func (*PdfMaroto) GetCurrentOffset

func (s *PdfMaroto) GetCurrentOffset() float64

GetCurrentOffset obtain the current offset in y axis

Example

ExamplePdfMaroto_GetCurrentOffset demonstrates how to obtain the current write offset i.e the height of cursor adding content in the pdf

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Offset here will be 0
	_ = m.GetCurrentOffset()

	// Add Rows, Cols and Components until maroto add a new page

	// Offset here will not be 0
	_ = m.GetCurrentOffset()

	// Add Rows, Cols and Components to maroto add a new page

	// Offset here will be 0
	_ = m.GetCurrentOffset()

	// Do more things and save...
}
Output:

func (*PdfMaroto) GetCurrentPage

func (s *PdfMaroto) GetCurrentPage() int

GetCurrentPage obtain the current page index this can be used inside a RegisterFooter/RegisterHeader to draw the current page, or to another purposes

Example

ExamplePdfMaroto_GetCurrentPage demonstrates how to obtain the current page index

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Index here will be 0
	_ = m.GetCurrentPage()

	// Add Rows, Cols and Components

	// Index here will not be 0
	_ = m.GetCurrentPage()

	// Do more things and save...
}
Output:

func (*PdfMaroto) GetPageMargins

func (s *PdfMaroto) GetPageMargins() (left float64, top float64, right float64, bottom float64)

GetPageMargins returns the set page margins. Comes in order of Left, Top, Right, Bottom Default page margins is left: 10, top: 10, right: 10

Example

ExamplePdfMaroto_GetPageMargins demonstrates how to obtain the current page margins

package main

import (
	"fmt"

	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Get
	left, top, right, bottom := m.GetPageMargins()
	fmt.Println(left)
	fmt.Println(top)
	fmt.Println(right)
	fmt.Println(bottom)

	// Do more things and save...
}
Output:

func (*PdfMaroto) GetPageSize

func (s *PdfMaroto) GetPageSize() (width float64, height float64)

GetPageSize return the actual page size

Example

ExamplePdfMaroto_GetPageSize demonstrates how to obtain the current page size (width and height)

package main

import (
	"fmt"

	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Get
	width, height := m.GetPageSize()
	fmt.Println(width)
	fmt.Println(height)

	// Do more things and save...
}
Output:

func (*PdfMaroto) Line

func (s *PdfMaroto) Line(spaceHeight float64)

Line draw a line from margin left to margin right in the currently row.

Example

ExamplePdfMaroto_Line demonstrates how to draw a line separator.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	m.Line(1.0)

	// Do more things and save...
}
Output:

func (*PdfMaroto) Output

func (s *PdfMaroto) Output() (bytes.Buffer, error)

Output extract PDF in byte slices

Example

ExamplePdfMaroto_Output demonstrates how to get a base64 string from PDF

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Do a lot of things on rows and columns...

	_, err := m.Output()
	if err != nil {
		return
	}
}
Output:

func (*PdfMaroto) OutputFileAndClose

func (s *PdfMaroto) OutputFileAndClose(filePathName string) (err error)

OutputFileAndClose save pdf in disk.

Example

ExamplePdfMaroto_OutputFileAndClose demonstrates how to save a PDF object into disk.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Do a lot of things on rows and columns...

	err := m.OutputFileAndClose("path/file.pdf")
	if err != nil {
		return
	}
}
Output:

func (*PdfMaroto) QrCode

func (s *PdfMaroto) QrCode(code string, prop ...props.Rect)

QrCode create a qrcode inside a cell.

Example

ExamplePdfMaroto_QrCode demonstrates how to add a QR Code inside a Col.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// Passing nil on rectProps makes
	// the QR Code fills the context cell.
	// When center is true, left and top has no effect.
	// Percent represents the width/height of the QR Code inside the cell.
	// i.e. 80 means that the QR Code will take up 80% of Col's width
	// When center is false, positioning of the QR Code can be done through
	// left and top.

	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	m.Row(rowHeight, func() {
		m.Col(12, func() {
			m.QrCode("https://godoc.org/github.com/terinyo/maroto", props.Rect{
				Left:    5,
				Top:     5,
				Center:  false,
				Percent: 80,
			})
		})
	})
}
Output:

func (*PdfMaroto) RegisterFooter

func (s *PdfMaroto) RegisterFooter(closure func())

RegisterFooter define a sequence of Rows, Lines ou TableLists which will be added in every new page

Example

ExamplePdfMaroto_RegisterFooter demonstrates how to register footer.

package main

import (
	"time"

	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// For register footer you need to call method RegisterFooter
	// that receives a closure.
	// In this closure you are free to set any components you want to compose
	// your footer.
	// In this example there is a signature and a text with right align.
	// It is important to remember that it is recommended to create Row's and
	// Col's if necessary.
	// You have to register the footer immediately after the Maroto

	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	m.RegisterFooter(func() {
		m.Row(10, func() {
			m.Col(6, func() {
				m.Signature("lorem ipsum dolor")
			})
			m.Col(6, func() {
				m.Text(time.Now().Format("02-January-2006"), props.Text{Align: consts.Right})
			})
		})
	})

	// Do more things or not and save...
}
Output:

func (*PdfMaroto) RegisterHeader

func (s *PdfMaroto) RegisterHeader(closure func())

RegisterHeader define a sequence of Rows, Lines ou TableLists which will be added in every new page

Example

ExamplePdfMaroto_RegisterHeader demonstrates how to register header.

package main

import (
	"time"

	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// For register header in Maroto you need to call method RegisterHeader
	// that receives a closure.
	// In this closure you are free to set any components you want to compose
	// your header.
	// In this example there is a two texts with different props and one image.
	// It is important to remember that it is recommended to create Row's and
	// Col's if necessary.
	// You have to register the header immediately after the Maroto

	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	m.RegisterHeader(func() {
		m.Row(10, func() {
			m.Col(3, func() {
				m.Text("lorem ipsum dolor", props.Text{Align: consts.Left})
			})
			m.Col(3, func() {
				_ = m.FileImage("internal/assets/images/frontpage.png")
			})
			m.Col(3, func() {
				m.Text(time.Now().Format("02-January-2006"),
					props.Text{Align: consts.Right})
			})
		})
	})

	// Do more things or not and save...
}
Output:

func (*PdfMaroto) Row

func (s *PdfMaroto) Row(height float64, closure func())

Row define a row and enable add columns inside the row.

Example

ExamplePdfMaroto_Row demonstrates how to define a row.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	m.Row(rowHeight, func() {
		// ... Add some columns
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) SetAliasNbPages

func (s *PdfMaroto) SetAliasNbPages(alias string)

SetAliasNbPages Defines an alias for the total number of pages. It will be substituted as the document is closed.

Example

ExamplePdfMaroto_SetAliasNbPages demonstrates how to use SetAliasNbPages method.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Ths will create placeholder "{nbs}" to use in texts for total count of pages
	m.SetAliasNbPages("{nbs}")

	// This will create a row with full width column and inside it a text that will display the total number of pages
	m.Row(10, func() {
		m.Col(12, func() {
			m.Text("Total number of pages: {nbs}")
		})
	})
}
Output:

func (*PdfMaroto) SetBackgroundColor

func (s *PdfMaroto) SetBackgroundColor(color color.Color)

SetBackgroundColor define the background color of the PDF. This method can be used to toggle background from rows

Example

ExamplePdfMaroto_SetBackgroundColor demonstrates how to use the SetBackgroundColor method.

package main

import (
	"github.com/terinyo/maroto/pkg/color"
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	m.SetBackgroundColor(color.Color{
		Red:   100,
		Green: 20,
		Blue:  30,
	})

	// This Row will be filled with the color
	m.Row(20, func() {
		m.Col(12, func() {
			// Add components
		})
	})

	m.SetBackgroundColor(color.NewWhite())
	// Note: The default value is White (255, 255, 255), if maroto see this value it will ignore not will the cell with any color

	// This Row will not be filled with the color
	m.Row(20, func() {
		m.Col(12, func() {
			// Add components
		})
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) SetBorder

func (s *PdfMaroto) SetBorder(on bool)

SetBorder enable the draw of lines in every cell. Draw borders in all columns created.

Example

ExamplePdfMaroto_SetBorder demonstrates how to enable the line drawing in every cell

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	m.SetBorder(true)

	// Add some Rows, Cols, Lines and etc...
	// Here will be drawn borders in every cell

	m.SetBorder(false)

	// Add some Rows, Cols, Lines and etc...
	// Here will not be drawn borders

	// Do more things and save...
}
Output:

func (*PdfMaroto) SetFirstPageNb

func (s *PdfMaroto) SetFirstPageNb(number int)

SetFirstPageNb define first page number Default: 0

Example

ExamplePdfMaroto_SetFirstPageNb demonstrates how to use SetFirstPageNb method.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	// Ths will set first page index to 1
	m.SetFirstPageNb(1)
}
Output:

func (*PdfMaroto) SetPageMargins

func (s *PdfMaroto) SetPageMargins(left, top, right float64)

SetPageMargins overrides default margins (10,10,10) the new page margin will affect all PDF pages

Example

ExamplePdfMaroto_SetPageMargins demonstrates how to set custom page margins.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
)

func main() {
	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	m.SetPageMargins(10, 60, 10)

	// Do more things or not and save...
}
Output:

func (*PdfMaroto) Signature

func (s *PdfMaroto) Signature(label string, prop ...props.Font)

Signature add a space for a signature inside a cell, the space will have a line and a text below

Example

ExamplePdfMaroto_Signature demonstrates how to add a Signature space inside a col.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// Not passing this font prop will lead the method to use all the follow values.
	// Not passing family, make method use arial.
	// Not passing style, make method use normal.
	// Not passing size, make method use 10.0.

	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	m.Row(rowHeight, func() {
		m.Col(12, func() {
			m.Signature("LabelForSignature", props.Font{
				Size:   12.0,
				Style:  consts.BoldItalic,
				Family: consts.Courier,
			})
		})
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) TableList

func (s *PdfMaroto) TableList(header []string, contents [][]string, prop ...props.TableList)

TableList create a table with multiple rows and columns. Headers define the amount of columns from each row. Headers have bold style, and localized at the top of table. Contents are array of arrays. Each array is one line.

Example

ExamplePdfMaroto_TableList demonstrates how to add a table with multiple rows and columns.

package main

import (
	"github.com/terinyo/maroto/pkg/color"
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// Not passing this table list prop will lead the method to use all the follow values.
	// Not passing HeaderProp.Size, make the method use 10.
	// Not passing HeaderProp.Family, make the method use arial.
	// Not passing HeaderProp.Style, make the method use bold.
	// Not passing HeaderProp.GridSizes, make the method use an array with same length
	// of header array, the values will be perfectly divided to make all columns with the same size.
	// Not passing Align, make the method to use left.
	// Not passing ContentProp.Size, make the method use 10.
	// Not passing ContentProp.Family, make the method use arial.
	// Not passing ContentProp.Style, make the method use normal.
	// Not passing Content.GridSizes, make the method use an array with same length
	// of content array in the first line, the values will be perfectly divided to make all columns with the same size.
	// Not passing HeaderContentSpace, will make the method use 4.

	m := pdf.NewMaroto(consts.Portrait, consts.A4)

	headers := []string{"Header1", "Header2"}
	contents := [][]string{
		{"Content1", "Content2"},
		{"Content3", "Content3"},
	}

	m.TableList(headers, contents, props.TableList{
		HeaderProp: props.TableListContent{
			Family:    consts.Arial,
			Style:     consts.Bold,
			Size:      11.0,
			GridSizes: []uint{3, 9},
		},
		ContentProp: props.TableListContent{
			Family:    consts.Courier,
			Style:     consts.Normal,
			Size:      10.0,
			GridSizes: []uint{3, 9},
		},
		Align: consts.Center,
		AlternatedBackground: &color.Color{
			Red:   100,
			Green: 20,
			Blue:  255,
		},
		HeaderContentSpace: 10.0,
		Line:               false,
	})

	// Do more things and save...
}
Output:

func (*PdfMaroto) Text

func (s *PdfMaroto) Text(text string, prop ...props.Text)

Text create a text inside a cell.

Example

ExamplePdfMaroto_Text demonstrates how to add a Text inside a col.

package main

import (
	"github.com/terinyo/maroto/pkg/consts"
	"github.com/terinyo/maroto/pkg/pdf"
	"github.com/terinyo/maroto/pkg/props"
)

func main() {
	// Not passing the text prop will lead to use all the follow default values.
	// Not passing family, makes the method use arial.
	// Not passing style, makes the method use normal.
	// Not passing size, makes the method use 10.0.
	// Not passing align, makes the method use left.
	// Not passing extrapolate, makes the method use false.
	// Top cannot be less than 0.
	// VerticalPadding cannot be less than 0.

	m := pdf.NewMaroto(consts.Portrait, consts.A4)
	rowHeight := 5.0

	m.Row(rowHeight, func() {
		m.Col(12, func() {
			m.Text("TextContent", props.Text{
				Size:            12.0,
				Style:           consts.BoldItalic,
				Family:          consts.Courier,
				Align:           consts.Center,
				Top:             1.0,
				Extrapolate:     false,
				VerticalPadding: 1.0,
			})
		})
	})

	// Do more things and save...
}
Output:

Jump to

Keyboard shortcuts

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