Example #1
0
func (r *pdfRenderer) DrawBar(rect image.Rectangle) {
	p := new(pdf.Path)
	p.Rectangle(pdf.Rectangle{
		Min: pdf.Point{pdf.Unit(rect.Min.X) / pdfCoordinateScale, pdf.Unit(rect.Min.Y) / pdfCoordinateScale},
		Max: pdf.Point{pdf.Unit(rect.Max.X) / pdfCoordinateScale, pdf.Unit(rect.Max.Y) / pdfCoordinateScale},
	})
	r.canvas.Fill(p)
}
Example #2
0
func TestRenderPdf(t *testing.T) {
	doc := pdf.New()
	p := doc.NewPage(pdf.USLetterWidth, pdf.USLetterHeight)
	p.Translate(0.5*pdf.Inch, 0.5*pdf.Inch)
	num := uint64(590123412345)
	for i := 0; i < 5; i++ {
		for j := 0; j < 10; j++ {
			code, _ := EAN13FromCode12(num)
			p1 := pdf.Point{pdf.Unit(i) * 1.5 * pdf.Inch, pdf.Unit(j) * 1 * pdf.Inch}
			p2 := pdf.Point{p1.X + 1.5*pdf.Inch, p1.Y + 1*pdf.Inch}
			rect := pdf.Rectangle{p1, p2}
			code.RenderPdf(p, rect, 0.13*pdf.Inch)
			num += 20
		}
	}
	p.Close()

	f, _ := os.Create("test.pdf")
	defer f.Close()
	doc.Encode(f)
}
Example #3
0
func (r *pdfRenderer) DrawDigit(digit int, rect image.Rectangle, fontSize int) {
	text := new(pdf.Text)
	text.SetFont(pdf.Helvetica, pdf.Unit(fontSize))
	text.Text(digitsString[digit])
	r.canvas.Push()
	r.canvas.Transform(
		1, 0, 0, -1,
		float32(rect.Min.X)/pdfCoordinateScale,
		float32(rect.Min.Y)/pdfCoordinateScale+float32(pdfFontAscender*fontSize)/pdfFontUnitScale)
	r.canvas.DrawText(text)
	r.canvas.Pop()
}