Code Monkey home page Code Monkey logo

maroto's Introduction

Maroto

GoDoc Travis Codecov Go Report Card Mentioned in Awesome Go

A Maroto way to create PDFs. Maroto is inspired in Bootstrap and uses Gofpdf. Fast and simple.

Maroto definition: Brazilian expression, means an astute/clever/intelligent person.

You can write your PDFs like you are creating a site using Bootstrap. A Row may have many Cols, and a Col may have many components. Besides that, pages will be added when content may extrapolate the useful area. You can define a header which will be added always when a new page appear, in this case, a header may have many rows, lines or tablelist.

Installation

  • With go get:
go get -u github.com/eyesore/maroto

Features

result

Grid System

Components To Use Inside a Col

Components To Use Outside a Row

Components To Wrap Row, TableList and Line

Others

  • Properties: most of the components has properties which you can use to customize appearance and behavior.
  • SetBorder: Used to draw rectangles in every row and column
  • Automatic New Page: New pages are generated automatically when needed.
  • 100% Unicode
  • Save: You can save on disk or export to a base64 string

Roadmap

Examples

In the PDFs folder there are the PDFs generated using Maroto, and in the examples folder there are subfolders with the code to generate the PDFs.

result

Code

package main

import (
	"encoding/base64"
	"fmt"
	"github.com/eyesore/maroto/pkg/consts"
	"github.com/eyesore/maroto/pkg/pdf"
	"github.com/eyesore/maroto/pkg/props"
	"io/ioutil"
)

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

	byteSlices, _ := ioutil.ReadFile("internal/assets/images/biplane.jpg")

	base64 := base64.StdEncoding.EncodeToString(byteSlices)

	headerSmall, smallContent := getSmallContent()
	headerMedium, mediumContent := getMediumContent()

	m.RegisterHeader(func() {

		m.Row(20, func() {
			m.Col(func() {
				m.Base64Image(base64, consts.Jpg, props.Rect{
					Percent: 70,
				})
			})

			m.ColSpaces(2)

			m.Col(func() {
				m.QrCode("https://github.com/eyesore/maroto", props.Rect{
					Percent: 75,
				})
			})

			m.Col(func() {
				id := "https://github.com/eyesore/maroto"
				_ = m.Barcode(id, props.Barcode{
					Proportion: props.Proportion{50, 10},
					Percent:    75,
				})
				m.Text(id, props.Text{
					Size:  7,
					Align: consts.Center,
					Top:   16,
				})
			})
		})

		m.Line(1.0)

		m.Row(12, func() {
			m.Col(func() {
				m.FileImage("internal/assets/images/gopherbw.png")
			})

			m.ColSpace()

			m.Col(func() {
				m.Text("Packages Report: Daily", props.Text{
					Top: 4,
				})
				m.Text("Type: Small, Medium", props.Text{
					Top: 10,
				})
			})

			m.ColSpace()

			m.Col(func() {
				m.Text("20/07/1994", props.Text{
					Size:   10,
					Style:  consts.BoldItalic,
					Top:    7.5,
					Family: consts.Helvetica,
				})
			})
		})

		m.Line(1.0)

		m.Row(22, func() {
			m.Col(func() {
				m.Text(fmt.Sprintf("Small: %d, Medium %d", len(smallContent), len(mediumContent)), props.Text{
					Size:  15,
					Style: consts.Bold,
					Align: consts.Center,
					Top:   9,
				})
				m.Text("Brasil / São Paulo", props.Text{
					Size:  12,
					Align: consts.Center,
					Top:   17,
				})
			})
		})

		m.Line(1.0)

	})

	m.RegisterFooter(func() {
		m.Row(40, func() {
			m.Col(func() {
				m.Signature("Signature 1", props.Font{
					Family: consts.Courier,
					Style:  consts.BoldItalic,
					Size:   9,
				})
			})

			m.Col(func() {
				m.Signature("Signature 2")
			})

			m.Col(func() {
				m.Signature("Signature 3")
			})
		})
	})

	m.Row(15, func() {
		m.Col(func() {
			m.Text("Small Packages / 39u.", props.Text{
				Top:   8,
				Style: consts.Bold,
			})
		})
	})

	m.TableList(headerSmall, smallContent)

	m.Row(15, func() {
		m.Col(func() {
			m.Text("Medium Packages / 22u.", props.Text{
				Top:   8,
				Style: consts.Bold,
			})
		})
	})

	m.TableList(headerMedium, mediumContent, props.TableList{
		Align: consts.Center,
		HeaderProp: props.Font{
			Family: consts.Courier,
			Style:  consts.BoldItalic,
		},
		ContentProp: props.Font{
			Family: consts.Courier,
			Style:  consts.Italic,
		},
	})

	_ = m.OutputFileAndClose("internal/examples/pdfs/sample1.pdf")
}

Others

Stargazers over time

Stargazers over time

maroto's People

Contributors

johnfercher avatar johnferchermeli avatar suddengunter avatar nadams3 avatar soulspark666 avatar manoelstilpen avatar apissurno avatar aquarat avatar kazuhirodk avatar pensu avatar stanleynguyen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.