(转)Go实战--golang中操作PDF(rsc.io/pdf、jung-kurt/gofpdf、signintech/gopdf)

发布时间:2018-03-09编辑:lianpenglin阅读(4930)

    PDF简介

    The Portable Document Format (PDF) is a file format used to present documents in a manner independent of application software, hardware, and operating systems.[3] Each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, graphics, and other information needed to display it.

    pdf(Portable Document Format的简称,意为“便携式文档格式”),是由Adobe Systems用于与应用程序、操作系统、硬件无关的方式进行文件交换所发展出的文件格式。PDF文件以PostScript语言图象模型为基础,无论在哪种打印机上都可保证精确的颜色和准确的打印效果,即PDF会忠实地再现原稿的每一个字符、颜色以及图象。

    rsc.io/pdf

    github地址: 

    https://github.com/rsc/pdf

    Star: 202

    文档地址: 
    https://godoc.org/rsc.io/pdf

    获取:

    go get rsc.io/pdf

    读取PDF文件,获取总页数

    package main
    import (
        "fmt"
        "rsc.io/pdf"
    )
    func main() {
        file, err := pdf.Open("go.pdf")
        if err != nil {
            panic(err)
        }
        fmt.Println(file.NumPage())
    }

    读取某一页的内容

    package main
    import (
        "fmt"
        "rsc.io/pdf"
    )
    func main() {
        file, err := pdf.Open("test.pdf")
        if err != nil {
            panic(err)
        }
        fmt.Println(file.Page(2).Content())
    }


标签

如果对你有用打赏一下吧!