{"id":37150163,"url":"https://github.com/echa/gofpdf","last_synced_at":"2026-01-14T17:44:01.480Z","repository":{"id":57582131,"uuid":"101879187","full_name":"echa/gofpdf","owner":"echa","description":"A PDF document generator with high level support for text, drawing and images","archived":false,"fork":true,"pushed_at":"2017-08-30T13:40:19.000Z","size":3978,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T15:50:29.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/jung-kurt/gofpdf","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jung-kurt/gofpdf","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/echa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-30T12:36:38.000Z","updated_at":"2017-08-30T12:36:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/echa/gofpdf","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/echa/gofpdf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echa%2Fgofpdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echa%2Fgofpdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echa%2Fgofpdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echa%2Fgofpdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/echa","download_url":"https://codeload.github.com/echa/gofpdf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echa%2Fgofpdf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28428929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T17:44:00.785Z","updated_at":"2026-01-14T17:44:01.475Z","avatar_url":"https://github.com/echa.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gofpdf\n\n![gofpdf](image/logo_gofpdf.jpg?raw=true \"gofpdf\")\n\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/jung-kurt/gofpdf/master/license.txt)\n[![GoDoc](https://godoc.org/github.com/jung-kurt/gofpdf?status.svg)](https://godoc.org/github.com/jung-kurt/gofpdf)\n[![Build Status](https://travis-ci.org/jung-kurt/gofpdf.svg?branch=master)](https://travis-ci.org/jung-kurt/gofpdf)\n\nPackage gofpdf implements a PDF document generator with high level support for\ntext, drawing and images.\n\n## Features\n\n* Choice of measurement unit, page format and margins\n* Page header and footer management\n* Automatic page breaks, line breaks, and text justification\n* Inclusion of JPEG, PNG, GIF, TIFF and basic path-only SVG images\n* Colors, gradients and alpha channel transparency\n* Outline bookmarks\n* Internal and external links\n* TrueType, Type1 and encoding support\n* Page compression\n* Lines, Bézier curves, arcs, and ellipses\n* Rotation, scaling, skewing, translation, and mirroring\n* Clipping\n* Document protection\n* Layers\n* Templates\n* Barcodes\n\ngofpdf has no dependencies other than the Go standard library. All tests pass\non Linux, Mac and Windows platforms.\n\nLike FPDF version 1.7, from which gofpdf is derived, this package does not yet\nsupport UTF-8 fonts. In particular, languages that require more than one code\npage such as Chinese, Japanese, and Arabic are not currently supported. This is\nexplained in [issue 109](https://github.com/jung-kurt/gofpdf/issues/109). However, support is provided to automatically translate\nUTF-8 runes to code page encodings for languages that have fewer than 256\nglyphs.\n\n## Installation\n\n\nTo install the package on your system, run\n\n```\ngo get github.com/jung-kurt/gofpdf\n```\n\nLater, to receive updates, run\n\n```\ngo get -u -v github.com/jung-kurt/gofpdf/...\n```\n\n## Quick Start\n\n\nThe following Go code generates a simple PDF file.\n\n```\npdf := gofpdf.New(\"P\", \"mm\", \"A4\", \"\")\npdf.AddPage()\npdf.SetFont(\"Arial\", \"B\", 16)\npdf.Cell(40, 10, \"Hello, world\")\nerr := pdf.OutputFileAndClose(\"hello.pdf\")\n```\n\nSee the functions in the [fpdf_test.go](https://github.com/jung-kurt/gofpdf/blob/master/fpdf_test.go) file (shown as examples in this\ndocumentation) for more advanced PDF examples.\n\n## Errors\n\n\nIf an error occurs in an Fpdf method, an internal error field is set. After\nthis occurs, Fpdf method calls typically return without performing any\noperations and the error state is retained. This error management scheme\nfacilitates PDF generation since individual method calls do not need to be\nexamined for failure; it is generally sufficient to wait until after Output()\nis called. For the same reason, if an error occurs in the calling application\nduring PDF generation, it may be desirable for the application to transfer the\nerror to the Fpdf instance by calling the SetError() method or the SetErrorf()\nmethod. At any time during the life cycle of the Fpdf instance, the error state\ncan be determined with a call to Ok() or Err(). The error itself can be\nretrieved with a call to Error().\n\n## Conversion Notes\n\n\nThis 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\nGo](https://golang.org/doc/effective_go.html)). The API names have been retained even though the Go idiom would suggest\notherwise (for example, pdf.GetX() is used rather than simply pdf.X()). The\nsimilarity of the two libraries makes the original FPDF website a good source\nof information. It includes a forum and FAQ.\n\nHowever, some internal changes have been made. Page content is built up using\nbuffers (of type bytes.Buffer) rather than repeated string concatenation.\nErrors are handled as explained above rather than panicking. Output is\ngenerated through an interface of type io.Writer or io.WriteCloser. A number of\nthe original PHP methods behave differently based on the type of the arguments\nthat are passed to them; in these cases additional methods have been exported\nto provide similar functionality. Font definition files are produced in JSON\nrather than PHP.\n\n## Example PDFs\n\n\nA side effect of running \"go test ./...\" is the production of a number of\nexample PDFs. These can be found in the gofpdf/pdf directory after the tests\ncomplete.\n\nPlease note that these examples run in the context of a test. In order run an\nexample as a standalone application, you'll need to examine [fpdf_test.go](https://github.com/jung-kurt/gofpdf/blob/master/fpdf_test.go) for\nsome helper routines, for example exampleFilename() and summary().\n\nExample PDFs can be compared with reference copies in order to verify that they\nhave been generated as expected. This comparison will be performed if a PDF\nwith the same name as the example PDF is placed in the gofpdf/pdf/reference\ndirectory. The routine that summarizes an example will look for this file and,\nif found, will call ComparePDFFiles() to check the example PDF for equality\nwith its reference PDF. If differences exist between the two files they will be\nprinted to standard output and the test will fail. If the reference file is\nmissing, the comparison is considered to succeed. In order to successfully\ncompare two PDFs, the placement of internal resources must be consistent and\nthe internal creation timestamps must be the same. To do this, the methods\nSetCatalogSort() and SetCreationDate() need to be called for both files. This\nis done automatically for all examples.\n\n## Nonstandard Fonts\n\n\nNothing special is required to use the standard PDF fonts (courier, helvetica,\ntimes, zapfdingbats) in your documents other than calling SetFont().\n\nIn order to use a different TrueType or Type1 font, you will need to generate a\nfont definition file and, if the font will be embedded into PDFs, a compressed\nversion of the font file. This is done by calling the MakeFont function or\nusing the included makefont command line utility. To create the utility, cd\ninto the makefont subdirectory and run \"go build\". This will produce a\nstandalone executable named makefont. Select the appropriate encoding file from\nthe font subdirectory and run the command as in the following example.\n\n```\n./makefont --embed --enc=../font/cp1252.map --dst=../font ../font/calligra.ttf\n```\n\nIn your PDF generation code, call AddFont() to load the font and, as with the\nstandard fonts, SetFont() to begin using it. Most examples, including the\npackage example, demonstrate this method. Good sources of free, open-source\nfonts include [Google Fonts](http://www.google.com/fonts/) and [DejaVu Fonts](http://dejavu-fonts.org/).\n\n## Related Packages\n\n\nThe [draw2d](https://github.com/llgcode/draw2d) package is a two dimensional\nvector graphics library that can generate output in different forms. It uses\ngofpdf for its document production mode.\n\n## Contributing Changes\n\n\ngofpdf is a global community effort and you are invited to make it even better.\nIf you have implemented a new feature or corrected a problem, please consider\ncontributing your change to the project. A contribution that does not directly\npertain to the core functionality of gofpdf should be placed in its own\ndirectory directly beneath the `contrib` directory.\n\nHere are guidelines for making submissions. Your change should\n\n* be compatible with the MIT License\n* be properly documented\n* be formatted with `go fmt`\n* include an example in [fpdf_test.go](https://github.com/jung-kurt/gofpdf/blob/master/fpdf_test.go) if appropriate\n* conform to the standards of [golint](https://github.com/golang/lint) and\n[go vet](https://godoc.org/golang.org/x/tools/cmd/vet), that is, `golint .` and\n`go vet .` should not generate any warnings\n* not diminish [test coverage](https://blog.golang.org/cover)\n\n[Pull requests](https://help.github.com/articles/using-pull-requests/) work\nnicely as a means of contributing your changes.\n\n## License\n\n\ngofpdf is released under the MIT License. It is copyrighted by Kurt Jung and\nthe contributors acknowledged below.\n\n## Acknowledgments\n\n\nThis package's code and documentation are closely derived from the [FPDF](http://www.fpdf.org/) library created by Olivier Plathey, and a number of font and\nimage resources are copied directly from it. Drawing support is adapted from\nthe FPDF geometric figures script by David Hernández Sanz. Transparency\nsupport is adapted from the FPDF transparency script by Martin Hall-May.\nSupport for gradients and clipping is adapted from FPDF scripts by Andreas\nWürmser. Support for outline bookmarks is adapted from Olivier Plathey by\nManuel Cornes. Layer support is adapted from Olivier Plathey. Support for\ntransformations is adapted from the FPDF transformation script by Moritz Wagner\nand Andreas Würmser. PDF protection is adapted from the work of Klemen\nVodopivec for the FPDF product. Lawrence Kesteloot provided code to allow an\nimage's extent to be determined prior to placement. Support for vertical\nalignment within a cell was provided by Stefan Schroeder. Ivan Daniluk\ngeneralized the font and image loading code to use the Reader interface while\nmaintaining backward compatibility. Anthony Starks provided code for the\nPolygon function. Robert Lillack provided the Beziergon function and corrected\nsome naming issues with the internal curve function. Claudio Felber provided\nimplementations for dashed line drawing and generalized font loading. Stani\nMichiels provided support for multi-segment path drawing with smooth line\njoins, line join styles, enhanced fill modes, and has helped greatly with\npackage presentation and tests. Templating is adapted by Marcus Downing from\nthe FPDF_Tpl library created by Jan Slabon and Setasign. Jelmer Snoeck\ncontributed packages that generate a variety of barcodes and help with\nregistering images on the web. Jelmer Snoek and Guillermo Pascual augmented the\nbasic HTML functionality with aligned text. Kent Quirk implemented\nbackwards-compatible support for reading DPI from images that support it, and\nfor setting DPI manually and then having it properly taken into account when\ncalculating image size. Paulo Coutinho provided support for static embedded\nfonts. Dan Meyers added support for embedded JavaScript. Bruno Michel has\nprovided valuable assistance with the code.\n\n## Roadmap\n\n* Handle UTF-8 source text natively. Until then, automatic translation of\nUTF-8 runes to code page bytes is provided.\n* Improve test coverage as reported by the coverage tool.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecha%2Fgofpdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecha%2Fgofpdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecha%2Fgofpdf/lists"}