# gofpdf
![gofpdf](image/logo_gofpdf.jpg?raw=true "gofpdf")
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/jung-kurt/gofpdf/master/license.txt)
[![GoDoc](https://godoc.org/github.com/jung-kurt/gofpdf?status.svg)](https://godoc.org/github.com/jung-kurt/gofpdf)
[![Build Status](https://travis-ci.org/jung-kurt/gofpdf.svg?branch=master)](https://travis-ci.org/jung-kurt/gofpdf)
Package gofpdf implements a PDF document generator with high level support for
text, drawing and images.
## Features
* Choice of measurement unit, page format and margins
* Page header and footer management
* Automatic page breaks, line breaks, and text justification
* Inclusion of JPEG, PNG, GIF, TIFF and basic path-only SVG images
* Colors, gradients and alpha channel transparency
* Outline bookmarks
* Internal and external links
* TrueType, Type1 and encoding support
* Page compression
* Lines, Bézier curves, arcs, and ellipses
* Rotation, scaling, skewing, translation, and mirroring
* Clipping
* Document protection
* Layers
* Templates
* Barcodes
gofpdf has no dependencies other than the Go standard library. All tests pass
on Linux, Mac and Windows platforms.
Like FPDF version 1.7, from which gofpdf is derived, this package does not yet
support UTF-8 fonts. In particular, languages that require more than one code
page such as Chinese, Japanese, and Arabic are not currently supported. This is
explained in [issue 109](https://github.com/jung-kurt/gofpdf/issues/109). However, support is provided to automatically translate
UTF-8 runes to code page encodings for languages that have fewer than 256
glyphs.
## Installation
To install the package on your system, run
```
go get github.com/jung-kurt/gofpdf
```
Later, to receive updates, run
```
go get -u -v github.com/jung-kurt/gofpdf/...
```
## Quick Start
The following Go code generates a simple PDF file.
```
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
pdf.Cell(40, 10, "Hello, world")
err := pdf.OutputFileAndClose("hello.pdf")
```
See the functions in the [fpdf_test.go](https://github.com/jung-kurt/gofpdf/blob/master/fpdf_test.go) file (shown as examples in this
documentation) for more advanced PDF examples.
## Errors
If an error occurs in an Fpdf method, an internal error field is set. After
this occurs, Fpdf method calls typically return without performing any
operations and the error state is retained. This error management scheme
facilitates PDF generation since individual method calls do not need to be
examined for failure; it is generally sufficient to wait until after Output()
is called. For the same reason, if an error occurs in the calling application
during PDF generation, it may be desirable for the application to transfer the
error to the Fpdf instance by calling the SetError() method or the SetErrorf()
method. At any time during the life cycle of the Fpdf instance, the error state
can be determined with a call to Ok() or Err(). The error itself can be
retrieved with a call to Error().
## Conversion Notes
This package is a relatively straightforward translation from the original [FPDF](http://www.fpdf.org/) library written in PHP (despite the caveat in the introduction to [Effective
Go](https://golang.org/doc/effective_go.html)). The API names have been retained even though the Go idiom would suggest
otherwise (for example, pdf.GetX() is used rather than simply pdf.X()). The
similarity of the two libraries makes the original FPDF website a good source
of information. It includes a forum and FAQ.
However, some internal changes have been made. Page content is built up using
buffers (of type bytes.Buffer) rather than repeated string concatenation.
Errors are handled as explained above rather than panicking. Output is
generated through an interface of type io.Writer or io.WriteCloser. A number of
the original PHP methods behave differently based on the type of the arguments
that are passed to them; in these cases additional methods have been exported
to provide similar functionality. Font definition files are produced in JSON
rather than PHP.
## Example PDFs
A side effect of running "go test ./..." is the production of a number of
example PDFs. These can be found in the gofpdf/pdf directory after the tests
complete.
Please note that these examples run in the context of a test. In order run an
example as a standalone application, you'll need to examine [fpdf_test.go](https://github.com/jung-kurt/gofpdf/blob/master/fpdf_test.go) for
some helper routines, for example exampleFilename() and summary().
Example PDFs can be compared with reference copies in order to verify that they
have been generated as expected. This comparison will be performed if a PDF
with the same name as the example PDF is placed in the gofpdf/pdf/reference
directory. The routine that summarizes an example will look for this file and,
if found, will call ComparePDFFiles() to check the example PDF for equality
with its reference PDF. If differences exist between the two files they will be
printed to standard output and the test will fail. If the reference file is
missing, the comparison is considered to succeed. In order to successfully
compare two PDFs, the placement of internal resources must be consistent and
the internal creation timestamps must be the same. To do this, the methods
SetCatalogSort() and SetCreationDate() need to be called for both files. This
is done automatically for all examples.
## Nonstandard Fonts
Nothing special is required to use the standard PDF fonts (courier, helvetica,
times, zapfdingbats) in your documents other than calling SetFont().
In order to use a different TrueType or Type1 font, you will need to generate a
font definition file and, if the font will be embedded into PDFs, a compressed
version of the font file. This is done by calling the MakeFont function or
using the included makefont command line utility. To create the utility, cd
into the makefont subdirectory and run "go build". This will produce a
standalone executable named makefont. Select the appropriate encoding file from
the font subdirectory and run the command as in the following example.
```
./makefont --embed --enc=../font/cp1252.map --dst=../font ../font/calligra.ttf
```
In your PDF generation code, call AddFont() to load the font and, as with the
standard fonts, SetFont() to begin using it. Most examples, including the
package example, demonstrate this method. Good sources of free, open-source
fonts include [Google Fonts](http://www.google.com/fonts/) and [DejaVu Fonts](http://dejavu-fonts.org/).
## Related Packages
The [draw2d](https://github.com/llgcode/draw2d) package is a two dimensional
vector graphics library that can generate output in different forms. It uses
gofpdf for its document production mode.
## Contributing Changes
gofpdf is a global community effort and you are invited to make it even better.
If you have implemented a new feature or corrected a problem, please consider
contributing your change to the project. A contribution that does not directly
pertain to the core functionality of gofpdf should be placed in its own
directory directly beneath the `contrib` directory.
Here are guidelines for making submissions. Your change should
* be compatible with the MIT License
* be properly documented
* be formatted with `go fmt`
* include an example in [fpdf_test.go](https://github.com/jung-kurt/gofpdf/blob/master/fpdf_test.go) if appropriate
* conform to the standards of [golint](https://github.com/golang/lint) and
[go vet](https://godoc.org/golang.org/x/tools/cmd/vet), that is, `golint .` and
`go vet .` should not generate any warnings
* not diminish [test coverage](https://blog.golang.org/cover)
[Pull requests](https://help.github.com/articles/using-pull-requests/) work
nicely as a means of contributing your changes.
## License
gofpdf is released under the MIT License. It is copyrighted by Kurt Jung and
the
没有合适的资源?快使用搜索试试~ 我知道了~
Go项目的实现书籍“使用Python自动化无聊的东西:初学者的实用编程”_Go_下载.zip
共992个文件
go:337个
txt:188个
png:183个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 103 浏览量
2023-04-22
16:21:42
上传
评论
收藏 71.46MB ZIP 举报
温馨提示
Go项目的实现书籍“使用Python自动化无聊的东西:初学者的实用编程”_Go_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
Go项目的实现书籍“使用Python自动化无聊的东西:初学者的实用编程”_Go_下载.zip (992个子文件)
AUTHORS 173B
AUTHORS 173B
AUTHORS 173B
AUTHORS 111B
AUTHORS 36B
ChangeLog 2KB
check 42B
CONTRIBUTORS 170B
CONTRIBUTORS 170B
CONTRIBUTORS 170B
COPYING 34KB
cov 63B
testCsv.csv 32B
testCsv.csv 32B
1.csv 27B
1.csv 27B
new_testCsv.csv 16B
new_testCsv.csv 16B
new_1.csv 12B
new_1.csv 12B
Dockerfile 174B
1.docx 4KB
1.docx 4KB
.gitattribute 13B
name.go 204KB
fpdf.go 113KB
entity.go 112KB
entity.go 112KB
parse.go 53KB
mib.go 49KB
parse.go 47KB
token.go 30KB
xmlStyle.go 27KB
table.go 27KB
read.go 27KB
lib.go 26KB
embedded.go 24KB
message.go 24KB
remote.go 23KB
transform.go 22KB
token.go 19KB
page.go 18KB
parser.go 18KB
reader.go 17KB
def.go 16KB
table.go 16KB
encoder.go 15KB
xmlWorksheet.go 14KB
goquery.go 14KB
resize.go 13KB
ini.go 13KB
client.go 13KB
font.go 12KB
templates.go 12KB
flags.go 12KB
decoder.go 12KB
cell.go 12KB
writer.go 12KB
selenium.go 11KB
sheet.go 10KB
doc.go 10KB
search.go 10KB
option.go 10KB
command.go 10KB
group.go 10KB
lex.go 10KB
encoding.go 9KB
versioninfo.go 9KB
help.go 9KB
file.go 9KB
ttfparser.go 9KB
proxy_participant.go 9KB
util.go 8KB
read.go 8KB
xmlWorkbook.go 8KB
seqset.go 8KB
reader.go 8KB
voice.go 8KB
webhooks.go 7KB
fitz.go 7KB
template.go 7KB
text.go 7KB
fpdftrans.go 7KB
render.go 7KB
render.go 7KB
cache.go 7KB
completion.go 7KB
convert.go 7KB
foreign.go 7KB
foreign.go 7KB
transform.go 7KB
cmd_selected.go 6KB
helpers.go 6KB
adjust.go 6KB
htmlbasic.go 6KB
mailbox.go 6KB
reader.go 6KB
escape.go 6KB
tools.go 6KB
escape.go 6KB
共 992 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功