pdf

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: MIT Imports: 5 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())
	RegisterHeader(closure func())
	Col(closure func())
	ColSpace()
	ColSpaces(qtd int)

	// Helpers
	SetDebugMode(on bool)
	GetDebugMode() bool
	GetPageSize() (float64, float64)

	// 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)
	Base64Image(base64 string, extension consts.Extension, prop ...props.Rect)
	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)
}

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.

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

	DebugMode bool
	// contains filtered or unexported fields
}

PdfMaroto is the principal structure which implements Maroto abstraction

func (*PdfMaroto) Barcode

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

Barcode create an barcode inside a cell.

func (*PdfMaroto) Base64Image

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

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

Example

ExamplePdfMaroto_Base64Image demonstrates how add a Image reading a base64 string. When barcodeProp is nil, method make Image fulfill the context cell, based on width and cell from Image and 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 with left and top.

package main

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

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

	m.Row(rowHeight, func() {
		m.Col(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 (self *PdfMaroto) Col(closure func())

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

Example

ExamplePdfMaroto_Col demonstrates how to add a useful column

package main

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

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

	m.Row(rowHeight, func() {
		m.Col(func() {
			// Add Image, Text, Signature, QrCode or Barcode...
		})
	})

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

func (*PdfMaroto) ColSpace

func (self *PdfMaroto) ColSpace()

ColSpace create an empty column inside a row.

Example

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

package main

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

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

	m.Row(rowHeight, func() {
		m.ColSpace()
	})

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

func (*PdfMaroto) ColSpaces

func (self *PdfMaroto) ColSpaces(qtd int)

ColSpace create some empty columns inside a row.

Example

ExamplePdfMaroto_ColSpaces demonstrates how to add some empty columns inside a row.

package main

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

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

	m.Row(rowHeight, func() {
		m.ColSpaces(2)
	})

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

func (*PdfMaroto) FileImage

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

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

Example

ExamplePdfMaroto_FileImage demonstrates how add a Image reading from disk. When barcodeProp is nil, method make Image fulfill the context cell, based on width and cell from Image and 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 with left and top.

package main

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

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

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

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

func (*PdfMaroto) GetDebugMode added in v0.14.0

func (self *PdfMaroto) GetDebugMode() bool

GetDebugMode return the actual debug mode.

Example

ExamplePdfMaroto_GetDebugMode demonstrates how to obtain the actual debug mode value

package main

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

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

	// false
	m.GetDebugMode()

	m.SetDebugMode(true)

	// true
	m.GetDebugMode()

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

func (*PdfMaroto) GetPageSize

func (self *PdfMaroto) GetPageSize() (float64, float64)

GetPageSize return the actual page size

func (*PdfMaroto) Line

func (self *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/johnfercher/maroto/pkg/consts"
	"github.com/johnfercher/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 (self *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/johnfercher/maroto/pkg/consts"
	"github.com/johnfercher/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 (self *PdfMaroto) OutputFileAndClose(filePathName string) (err error)

OutputFileAndClose save pdf in disk.

Example

ExamplePdfMaroto_OutputFileAndClose demonstrates how to save a PDF in disk.

package main

import (
	"github.com/johnfercher/maroto/pkg/consts"
	"github.com/johnfercher/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 (self *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. Passing nil on rectProps make make the QR Code fill the context cell, depending on width and height of the QR Code and the 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.

package main

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

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

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

func (*PdfMaroto) RegisterHeader

func (self *PdfMaroto) RegisterHeader(closure func())

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

func (*PdfMaroto) Row

func (self *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/johnfercher/maroto/pkg/consts"
	"github.com/johnfercher/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) SetDebugMode added in v0.14.0

func (self *PdfMaroto) SetDebugMode(on bool)

SetDebugMode enable debug mode. Draw borders in all columns created.

Example

ExamplePdfMaroto_SetDebugMode demonstrates how to define debug mode

package main

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

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

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

	m.SetDebugMode(false)

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

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

func (*PdfMaroto) Signature

func (self *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. Passing nil on signatureProp make the method use: arial Font, normal style and size 10.0. Not passing family, make method use arial. Not passing style, make method use normal. Not passing size, make method use 10.0.

package main

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

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

	m.Row(rowHeight, func() {
		m.Col(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 (self *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/johnfercher/maroto/pkg/consts"
	"github.com/johnfercher/maroto/pkg/pdf"
)

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

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

	// 1 Row of header
	// 2 Rows of contents
	// Each row have 2 columns
	m.TableList(headers, contents)

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

func (*PdfMaroto) Text

func (self *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. Passing nil on fontProp make the method use: arial Font, normal style, size 10.0 and align left. Not passing family, make method use arial. Not passing style, make method use normal. Not passing size, make method use 10.0. Not passing align, make method use left.

package main

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

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

	m.Row(rowHeight, func() {
		m.Col(func() {
			m.Text("TextContent", props.Text{
				Size:   12.0,
				Style:  consts.BoldItalic,
				Family: consts.Courier,
				Align:  consts.Center,
				Top:    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