Giter Club home page Giter Club logo

gopdf-wrapper's Introduction

gopdf-wrapper

GoDoc Go Report Card

The gopdf library is a great library for creating PDFs in golang. This wrapper provides some convince abstractions for recurring tasks. Like:

  • Maintain a default font size
  • Add formatted text
  • Add multiline text
  • Auto wrap text
  • gopdf-wrapper embeds the Lato font and Liberation Sans which is probably enough for simple reports

The code of this library is licensed under the MIT License the fonts (Lato and Liberation Sans) on the other hand are licensed under the SIL Open Font License (OFL).

Example

import (
	"github.com/72nd/gopdf-wrapper/fonts"
	wrapper "github.com/72nd/gopdf-wrapper"
)

// New document with font size 12 and line spread 1. 
doc, err := wrapper.NewDoc(12, 1)
if err != nil {
	t.Error(err)
}
liberation, err := fonts.NewLiberationSansFamily()
if err != nil {
	t.Error(err)
}
doc.SetFontFamily(*liberation)
doc.AddPage()

// Text
doc.AddFormattedText(10, 20, "This is a document", 25, "bold")
doc.AddSizedText(10, 20 + doc.LineHeight(25), "Some subtitle", 18)
doc.AddText(10, 40, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.")
doc.AddMultilineText(10, 50, "Ut enim ad minim veniam,\nquis nostrud exercitation ullamco laboris\nnisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit\nin voluptate velit esse cillum dolore\neu fugiat nulla pariatur.")
doc.AddWrapText(10, 80, 140, "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.")

// Lines
doc.AddLine(10, 140, 30, 160, 0.1, SolidLine)
doc.AddLine(10, 160, 30, 140, 0.1, SolidLine)
doc.AddLine(10, 150, 30, 150, 0.1, SolidLine)
doc.AddLine(20, 140, 20, 160, 0.1, SolidLine)

// Image
doc.Image("image.png", 10, 190, nil)

// Write document to PDF.
doc.WritePdf("document.pdf")

This generates the following output:

Output

gopdf-wrapper's People

Contributors

72nd 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.