Code Monkey home page Code Monkey logo

pdf's Introduction

Exercise #20: Building PDFs

exercise status: released

Exercise details

There are two goals with this exercise.

  1. Create a PDF invoice given some data about a fake customer's recent transactions
  2. Generate a course completion certificate for Gophercises and add your name to it!

Whoa, what?!? Yep, you read that right. Many courses will give you a course completion certification. This one teaches you to generate it yourself! Sweet, right? ๐Ÿ˜Ž

NOTE: The design part of creating PDFs can take a while, so don't get upset if this exercise takes you a few hours to get all those details right.

Creating a PDF invoice

Given data like the following, generate a PDF invoice.

data := []struct {
  UnitName       string
  PricePerUnit   int
  UnitsPurchased int
}{
  {
    UnitName:       "2x6 Lumber - 8'",
    PricePerUnit:   375, // in cents
    UnitsPurchased: 220,
  }, {
    UnitName:       "Drywall Sheet",
    PricePerUnit:   822, // in cents
    UnitsPurchased: 50,
  }, {
    UnitName:       "Paint",
    PricePerUnit:   1455, // in cents
    UnitsPurchased: 3,
  },
}

The invoice should look something like the image below, but you are free to add some custom flair or make changes as you see fit.

Screenshot of the invoice PDF

You may not do this all dynamically at first, but once you have your code working try to clean it up and make it easier to create dynamic invoices as the data you are provided changes. You can even try to come up with a way to add support for multiple pages.

Course Completion Certificate

Create a course completion certificate that dynamically inserts your name. Below is a rough example of the one we will be creating in the videos.

Screenshot of the course completion certificate PDF

Notes

Images (like the jumping gopher) are in the images directory.

I will be using the gofpdf package

You can find it here: https://github.com/jung-kurt/gofpdf

The docs are on godoc: https://godoc.org/github.com/jung-kurt/gofpdf

The library can take some time to get used to, especially some of the string arguments like alignment, fill, etc. It can also be confusing learning which function to use for text etc as each has its own pros and cons. Just experiment and a bit and try to get something working ๐Ÿ™‚

Bonus

Make the invoice and the course completion certificate look better, and make the invoice work for multiple pages of data.

pdf's People

Contributors

joncalhoun 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.