当前位置: 首页>>代码示例>>Golang>>正文


Golang GoPdf.AddTTFFont方法代码示例

本文整理汇总了Golang中github.com/signintech/gopdf.GoPdf.AddTTFFont方法的典型用法代码示例。如果您正苦于以下问题:Golang GoPdf.AddTTFFont方法的具体用法?Golang GoPdf.AddTTFFont怎么用?Golang GoPdf.AddTTFFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/signintech/gopdf.GoPdf的用法示例。


在下文中一共展示了GoPdf.AddTTFFont方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestHello

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
	}

}
开发者ID:doncalamari,项目名称:gopdf,代码行数:31,代码来源:hello_test.go

示例2: main

//gopdf had no mechanism for set italic ( pdf.SetFont("SOMEFONT", "I", 14) ), but you can do like this.
func main() {
	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("DejaVuSerif", "../ttf/DejaVuSerif.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}
	err = pdf.AddTTFFont("DejaVuSerif-Italic", "../ttf/DejaVuSerif-Italic.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.SetFont("DejaVuSerif", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "Hi! This is nomal.")
	pdf.Br(20)

	err = pdf.SetFont("DejaVuSerif-Italic", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "Hi! This is italic.")
	pdf.WritePdf("italic.pdf")
}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:33,代码来源:italic.go

示例3: main

func main() {
	pdf := gopdf.GoPdf{}

	pdf.Start(gopdf.Config{
		PageSize: gopdf.Rect{W: 595.28, H: 841.89}, //595.28, 841.89 = A4
		Protection: gopdf.PDFProtectionConfig{UseProtection: true,
			Permissions: gopdf.PermissionsPrint | gopdf.PermissionsCopy | gopdf.PermissionsModify,
			OwnerPass:   []byte("1234"),
			UserPass:    []byte("5555")},
	})

	pdf.AddPage()
	err := pdf.AddTTFFont("TakaoPGothic", "../ttf/TakaoPGothic.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.SetLineWidth(2)
	pdf.SetLineType("dashed")
	pdf.SetLineType("dotted")
	pdf.Line(10, 30, 585, 30)
	err = pdf.SetFont("TakaoPGothic", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}

	//#1 pic
	pdf.Image("../imgs/gopher.jpg", 200, 50, nil)

	pdf.Cell(nil, "こんにちは")
	pdf.Br(20)
	pdf.WritePdf("protect.pdf")
}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:34,代码来源:protect.go

示例4: main

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("TakaoPGothic", "../ttf/TakaoPGothic.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.SetFont("TakaoPGothic", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.SetX(0)
	text01 := "こんにちは"
	pdf.Cell(nil, text01)
	w01, _ := pdf.MeasureTextWidth(text01)
	pdf.SetY(20)
	pdf.SetX(w01)

	text02 := "i am a man."
	pdf.Cell(nil, text02)
	w02, _ := pdf.MeasureTextWidth(text02)
	pdf.SetY(30)
	pdf.SetX(w01 + w02)

	text03 := "done"
	pdf.Cell(nil, text03)

	fmt.Printf("MeasureTextWidth = %f\n", w01)
	pdf.WritePdf("m.pdf")
}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:34,代码来源:measure.go

示例5: main

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("Roboto", "../ttf/Roboto-Regular.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}
	fontSize := 24
	err = pdf.SetFont("Roboto", "", fontSize)
	if err != nil {
		log.Print(err.Error())
		return
	}
	//pdf.SetGrayFill(0.5)
	//pdf.Cell(nil, "Áa")

	//Measure Width
	text := "How can I cordinate the text that I want draw?"
	pdf.Cell(nil, text)

	realWidth, _ := pdf.MeasureTextWidth(text)
	fmt.Printf("realWidth = %f", realWidth)

	var parser core.TTFParser
	err = parser.Parse("../ttf/Roboto-Regular.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	//Measure Height
	//get  CapHeight (https://en.wikipedia.org/wiki/Cap_height)
	cap := float64(float64(parser.CapHeight()) * 1000.00 / float64(parser.UnitsPerEm()))
	//convert
	realHeight := cap * (float64(fontSize) / 1000.0)
	fmt.Printf("realHeight = %f", realHeight)
	//test
	pdf.Br(realHeight)
	pdf.Cell(nil, "How can I cordinate the text that I want draw?")
	pdf.Br(realHeight)
	pdf.Cell(nil, "How can I cordinate the text that I want draw?123")
	pdf.Br(realHeight)
	pdf.Cell(nil, "How can I cordinate the text that I want draw?456")

	pdf.WritePdf("hello.pdf")
}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:48,代码来源:main.go

示例6: main

/*
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
}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:22,代码来源:grayfill.go

示例7: main

func main() {
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{Unit: "mm", PageSize: gopdf.Rect{W: 210.0, H: 297.0}}) //595.28pt, 841.89pt = A4
	pdf.AddPage()
	err := pdf.AddTTFFont("DROID", "DroidSerif-Regular.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.SetFont("DROID", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "Hello world!")
	pdf.SetY(30.0)
	pdf.Cell(nil, "Привет мир!")

	pdf.SetGrayStroke(0.5)
	pdf.Oval(10, 200, 200, 250)

	pdf.WritePdf("hello.pdf")
}
开发者ID:plumbum,项目名称:go-samples,代码行数:24,代码来源:main.go

示例8: main

/*
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")
}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:39,代码来源:color.go

示例9: main

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()
	var err error
	err = pdf.AddTTFFont("loma", "../ttf/Loma.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	//#1 pic
	pdf.Image("../imgs/gopher.jpg", 200, 50, nil)
	err = pdf.SetFont("loma", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.SetX(250)
	pdf.SetY(200)
	pdf.Cell(nil, "gopher and gopher")

	pdf.WritePdf("image.pdf")
}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:24,代码来源:image.go

示例10: main

/*
Thank https://github.com/miiton for setLineType
*/
func main() {
	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("TakaoPGothic", "../ttf/TakaoPGothic.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.SetLineWidth(2)
	pdf.SetLineType("dashed")
	//pdf.SetLineType("dotted")
	pdf.Line(10, 30, 585, 30)

	err = pdf.SetFont("TakaoPGothic", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "こんにちは")
	pdf.Br(20)
	pdf.WritePdf("line.pdf")

}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:27,代码来源:line.go

示例11: main

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()
	var err error
	err = pdf.AddTTFFont("HDZB_5", "../ttf/wts11.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.AddTTFFont("TakaoPGothic", "../ttf/TakaoPGothic.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.AddTTFFont("loma", "../ttf/Loma.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.AddTTFFont("namum", "../ttf/NanumBarunGothic.ttf")

	//china
	err = pdf.SetFont("HDZB_5", "", 14)
	if err != nil {
		log.Printf(err.Error())
		return
	}

	err = pdf.AddTTFFont("Roboto", "../ttf/Roboto-Regular.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	pdf.Cell(nil, "Hello")
	pdf.Br(20)
	pdf.Cell(nil, "您好")
	pdf.Br(20)

	//japan
	err = pdf.SetFont("TakaoPGothic", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "こんにちは")
	pdf.Br(20)

	//thai
	err = pdf.SetFont("loma", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "สวัสดี")
	pdf.Br(20)

	//test composite glyph
	err = pdf.SetFont("Roboto", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "ÁÉÍÓÖŐÚÜŰ")
	pdf.Br(20)
	pdf.Cell(nil, "ÁÉÍÓÖŐÚÜŰ")
	pdf.Br(20)

	//korean
	err = pdf.SetFont("namum", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "안녕하세요")
	pdf.Br(20)

	pdf.WritePdf("hello2.pdf")

}
开发者ID:oneplus1000,项目名称:gopdfsample,代码行数:85,代码来源:hello2.go

示例12: TestHello2

func TestHello2(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()
	var err error
	err = pdf.AddTTFFont("HDZB_5", "./ttf/wts11.ttf")
	if err != nil {
		t.Error(err)
		return
	}

	err = pdf.AddTTFFont("TakaoPGothic", "./ttf/TakaoPGothic.ttf")
	if err != nil {
		t.Error(err)
		return
	}

	err = pdf.AddTTFFont("loma", "./ttf/Loma.ttf")
	if err != nil {
		t.Error(err)
		return
	}

	err = pdf.AddTTFFont("namum", "./ttf/NanumBarunGothic.ttf")

	//china
	err = pdf.SetFont("HDZB_5", "", 14)
	if err != nil {
		t.Error(err)
		return
	}
	pdf.Cell(nil, "Hello")
	pdf.Br(20)
	pdf.Cell(nil, "您好")
	pdf.Br(20)

	//japan
	err = pdf.SetFont("TakaoPGothic", "", 14)
	if err != nil {
		t.Error(err)
		return
	}
	pdf.Cell(nil, "こんにちは")
	pdf.Br(20)

	//thai
	err = pdf.SetFont("loma", "", 14)
	if err != nil {
		t.Error(err)
		return
	}
	pdf.Cell(nil, "สวัสดี")
	pdf.Br(20)

	//korean
	err = pdf.SetFont("namum", "", 14)
	if err != nil {
		t.Error(err)
		return
	}
	pdf.Cell(nil, "안녕하세요")

	data, err := pdf.GetBytesPdfReturnErr()
	if err != nil {
		t.Error(err)
		return
	}

	if len(data) <= 0 {
		t.Error(err)
		return
	}
}
开发者ID:doncalamari,项目名称:gopdf,代码行数:74,代码来源:hello_test.go


注:本文中的github.com/signintech/gopdf.GoPdf.AddTTFFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。