编程实践Golang 生成PDF

Posted 禅与计算机程序设计艺术

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编程实践Golang 生成PDF相关的知识,希望对你有一定的参考价值。

Golang 生成PDF

一个简单但是非常实用的pdf生成器!

安装:

    go get github.com/jung-kurt/gofpdf

代码:

package main

import (
    "github.com/jung-kurt/gofpdf"
)

func main() 
    err := GeneratePdf("hello.pdf")
    if err != nil 
        panic(err)
    


// GeneratePdf generates our pdf by adding text and images to the page
// then saving it to a file (name specified in params).
func GeneratePdf(filename string) error 

    pdf := gofpdf.New("P", "mm", "A4", "")
    pdf.AddPage()
    pdf.SetFont("Arial", "B", 16)

    // CellFormat(width, height, text, border, position after, align, fill, link, linkStr)
    pdf.CellFormat(190, 7, "Welcome to topgoer.com", "0", 0, "CM", false, 0, "")

    // ImageOptions(src, x, y, width, height, flow, options, link, linkStr)
    pdf.ImageOpti

以上是关于编程实践Golang 生成PDF的主要内容,如果未能解决你的问题,请参考以下文章

编程实践Golang 实现 Yaml编码和解码

编程实践Golang 获取HTTP请求的IP地址

编程实践Golang 实现中文分词

golang编程实践总结

编程实践Golang 字符串数组排序

编程实践Golang 实现雪花算法