Created
July 6, 2018 04:34
-
-
Save ajstarks/80d1f2621be5bb01a0a48eafd444d4af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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