本文整理汇总了Golang中github.com/signintech/gopdf.GoPdf.AddPage方法的典型用法代码示例。如果您正苦于以下问题:Golang GoPdf.AddPage方法的具体用法?Golang GoPdf.AddPage怎么用?Golang GoPdf.AddPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/signintech/gopdf.GoPdf
的用法示例。
在下文中一共展示了GoPdf.AddPage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}
示例2: 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
}
}
示例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")
}
示例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")
}
示例5: main
/*
Thank https://github.com/miiton for write draw oval.
*/
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()
pdf.SetLineWidth(1)
pdf.Oval(100, 200, 500, 500)
pdf.WritePdf("oval.pdf")
//fmt.Printf("")
}
示例6: 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")
}
示例7: 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
}
示例8: 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")
}
示例9: 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")
}
示例10: 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")
}
示例11: 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")
}
示例12: 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")
}
示例13: 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
}
}