Example #1
0
func main() {

	var b bytes.Buffer

	doc := pdf.NewPdfDoc(&b)

	w, h := dox2go.StandardSize(dox2go.PS_A4, dox2go.U_MM)

	page := doc.CreatePage(dox2go.U_MM, w, h, dox2go.PO_Portrait)

	s := page.Surface()

	s.LineWidth(2.0)

	p := dox2go.NewPath()
	p.Arc(110, 150, 25, 0, math.Pi*2)
	p.Close()
	s.Fg(dox2go.RGB(0, 0, 0))
	s.Stroke(p)
	s.Bg(dox2go.RGB(255, 255, 0))
	s.Fill(p)

	p = dox2go.NewPath()
	p.Move(99, 158)
	p.Arc(97, 158, 2, 0, math.Pi*2)
	p.Move(125, 158)
	p.Arc(123, 158, 2, 0, math.Pi*2)

	p.Move(97, 140)
	p.Curve(105, 130, 115, 130, 123, 140)
	p.Close()

	s.Bg(dox2go.RGB(255, 255, 255))
	s.Fill(p)
	s.Stroke(p)

	font := doc.CreateFont(pdf.FONT_Helvetica, dox2go.FS_Bold, 20)
	s.Bg(dox2go.RGB(0, 0, 0))
	s.Text(font, 50, 100, "Hello World!")

	doc.Close()

	f, err := os.Create("tmp.pdf")
	if err != nil {
		fmt.Println("Could not create tmp.pdf")
		return
	}
	n, err := b.WriteTo(f)
	fmt.Printf("Write %d bytes\n", n)
}
Example #2
0
func TestSimplePage(t *testing.T) {
	var b bytes.Buffer

	var f, err = os.Open("../gologo.png")
	if err != nil {
		panic(err)
	}

	img, err := png.Decode(f)
	if err != nil {
		panic(err)
	}

	d := NewPdfDoc(&b)

	pi := d.CreateImage(img)

	page := d.CreatePage(d2g.U_MM, d2g.StandardSize(d2g.PS_A4, d2g.U_MM), d2g.PO_Portrait)

	s := page.Surface()

	s.LineWidth(3)

	p := d2g.NewPath()
	p.Move(d2g.Point{40, 40})
	p.Line(d2g.Point{140, 40})
	p.Curve(d2g.Point{120, 20}, d2g.Point{60, 20}, d2g.Point{40, 40})
	p.Close()

	s.Bg(d2g.RGB(255, 255, 0))
	s.Fill(p)

	s.Fg(d2g.RGB(255, 0, 0))
	s.Stroke(p)

	font := d.CreateFont(FONT_Helvetica, d2g.FS_Bold, 20)

	s.Bg(d2g.RGB(0, 0, 0))
	s.PushState()
	s.Translate(d2g.Point{50, 150})
	s.Skew(1.0, 0.5)
	s.Text(font, d2g.Point{0, 0}, "(Hello\\)")
	s.PopState()

	font = d.CreateFont(FONT_Times, d2g.FS_Regular, 30)

	s.Bg(d2g.RGB(100, 100, 100))
	s.Text(font, d2g.Point{101, 129}, "wor Ƶ ld")

	s.Image(pi, d2g.Point{40, 180}, d2g.Size{153, 55})

	//s.Bg(RGB(0, 200, 255))
	//s.Text(font, Point{100, 130}, "world")

	d.Close()

	f, err = os.Create("tmp.pdf")
	if err != nil {
		t.Error("Could not create tmp.pdf")
	}
	b.WriteTo(f)
}