Skip to content

Instantly share code, notes, and snippets.

@ajstarks
Created July 6, 2018 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajstarks/80d1f2621be5bb01a0a48eafd444d4af to your computer and use it in GitHub Desktop.
Save ajstarks/80d1f2621be5bb01a0a48eafd444d4af to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/ajstarks/pdfgen"
"os"
)
func blist(p *pdfgen.PDFDoc, x, y, size, ls float64, list []string, color string) {
qsize := size/4
for _, s := range list {
p.Circle(x+qsize, y, qsize, color)
p.Text(x+size, y-qsize, s, "sans", size, color)
y -= size * ls
}
}
func nlist(p *pdfgen.PDFDoc, x, y, size, ls float64, list []string, color string) {
for i, s := range list {
p.Text(x, y, fmt.Sprintf("%d. %s", i+1, s), "sans", size, color)
y -= size * ls
}
}
func list(p *pdfgen.PDFDoc, x, y, size, ls float64, list []string, color string) {
for _, s := range list {
p.Text(x, y, s, "sans", size, color)
y -= size * ls
}
}
func grid(p *pdfgen.PDFDoc, width, height, interval float64, color string) {
bottom := interval
left := interval
for x := left; x < width; x += interval {
p.Line(x, 0, x, height, 0.5, color)
p.Text(x, bottom, fmt.Sprintf("%v", x), "sans", 8, "gray")
}
for y := bottom; y < height; y += interval {
p.Line(0, y, width, y, 0.5, color)
p.Text(left, y, fmt.Sprintf("%v", y), "sans", 8, "gray")
}
}
func main() {
width, height, linewidth := 11.0 * 72, 8.5 * 72, 2.0
items := []string{"text, image, list", "rect, ellipse, polygon", "line, arc, curve"}
p := pdfgen.NewDoc(os.Stdout, width, height)
p.Init(1)
p.NewPage(1)
p.Text(100, 512, "Deck Elements", "sans", 48, "black")
p.Image(400, 200, 640, 480, 50, "follow.jpg")
p.Text(400, 175, "Follow your dreams", "sans", 12, "gray")
blist(p, 100, 425, 24, 1.6, items, "black")
p.Rect(100, 85, 50, 30, "maroon")
p.Ellipse(225, 100, 25, 15, "green")
p.Polygon([]float64{300, 350, 300}, []float64{80, 100, 120}, "rgb(0,0,127)")
p.Line(400, 100, 450, 100, linewidth, "black")
p.Arc(525, 100, 25, 25, 0, 180, linewidth, "blue")
p.Curve(600, 100, 750, 180, 700, 100, linewidth, "black")
p.EndPage()
p.EndDoc()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment