Exemplo n.º 1
0
func TestHello(t *testing.T) {

	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{Unit: "pt", PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
	pdf.AddPage()
	err := pdf.AddTTFFont("HDZB_5", "./ttf/wts11.ttf")
	if err != nil {
		t.Error(err)
		return
	}

	err = pdf.SetFont("HDZB_5", "", 14)
	if err != nil {
		t.Error(err)
		return
	}

	pdf.SetGrayFill(0.5)
	pdf.Cell(nil, "您好")
	data, err := pdf.GetBytesPdfReturnErr()
	if err != nil {
		t.Error(err)
		return
	}

	if len(data) <= 0 {
		t.Error(err)
		return
	}

}
Exemplo n.º 2
0
/*
Thank https://github.com/douglasm for write setgray .
*/
func main() {
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
	pdf.AddPage()
	err := pdf.AddTTFFont("HDZB_5", "../ttf/wts11.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}
	err = pdf.SetFont("HDZB_5", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.SetGrayFill(0.5)
	pdf.Cell(nil, "您好")
	pdf.WritePdf("hello.pdf")
	//test
}
Exemplo n.º 3
0
/*
Thank https://github.com/miiton for write text color supported.
*/
func main() {
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
	pdf.AddPage()
	err := pdf.AddTTFFont("HDZB_5", "../ttf/wts11.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}
	err = pdf.SetFont("HDZB_5", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	//
	pdf.SetGrayFill(0.5)
	pdf.Cell(nil, "gray")

	pdf.SetTextColor(255, 0, 0)
	pdf.Br(20)
	pdf.Cell(nil, "red")

	pdf.SetTextColor(0, 0, 0)
	pdf.Br(20)
	pdf.Cell(nil, "gray")

	pdf.SetGrayFill(0)
	pdf.Br(20)
	pdf.Cell(nil, "black")

	pdf.SetTextColor(0, 0, 255)
	pdf.Br(20)
	pdf.Cell(nil, "blue")

	pdf.WritePdf("color.pdf")
}