Description
The main idea behind this project was:
"How small can I make a PDF generator for it to still be useful for 80% of common PDF generation needs?"
The result is a single .go file with less than 1999 lines of code.
one-file-pdf alternatives and similar packages
Based on the "GUI" category.
Alternatively, view one-file-pdf alternatives based on common mentions on social networks and blogs.
-
qt
Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly -
webview
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows) -
robotgo
RobotGo, Go Native cross-platform GUI automation @vcaesar -
app
A package to build progressive web apps with Go programming language and WebAssembly. -
go-astilectron
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron) -
systray
a cross platfrom Go library to place an icon and menu in the notification area -
sciter
Sciter: the Embeddable HTML/CSS/JS engine for modern UI development -
nuklear
This project provides Go bindings for nuklear.h — a small ANSI C GUI library. -
Guark
Build awesome Golang desktop apps and beautiful interfaces with Vue.js, React.js, Framework 7, and more... -
gosx-notifier
gosx-notifier is a Go framework for sending desktop notifications to OSX 10.8 or higher -
gowd
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs) -
go-thrust
Cross Platform UI Kit powered by Blink/V8/Chromium Content Lib -
trayhost
Cross-platform Go library to place an icon in the host operating system's taskbar. -
mac-sleep-notifier
macOS Sleep/ Wake notifications in golang -
mac-activity-tracker
A library to notify about any (pluggable) activity on your machine, and let you take action as needed -
go-appindicator
:traffic_light: Go bindings for libappindicator3 C library -
AppIndicator Go
:traffic_light: Go bindings for libappindicator3 C library -
gio
Gio is a library for writing cross-platform immediate mode GUI-s in Go. Gio supports all the major platforms: Linux, macOS, Windows, Android, iOS, FreeBSD, OpenBSD and WebAssembly.
Static code analysis for 29 languages.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of one-file-pdf or a related project?
README
one-file-pdf - A minimalist PDF generator in <2K lines and 1 file
The main idea behind this project was:
"How small can I make a PDF generator for it to still be useful for 80% of common PDF generation needs?"
The result is a single .go file with less than 1999 lines of code, about 400 of which are color and glyph-size constants, and ~350 are comments.
- It's easier to learn about the internals of the PDF format with a small, concise library.
- The current version of the file is indicated in the header (the timestamp).
Features:
- The essentials for generating PDF documents, sufficient for common business reports.
- Use all built-in PDF fonts: Courier, Helvetica, Symbol, Times, ZapfDingbats, and their variants
- Specify colo(u)rs by name (144 web colors), HTML codes (#RRGGBB) or RGB value
- Set columns for text (like tab stops on the page)
- Built-in grid option to help measurement and positioning
- Metadata properties: author, creator, keywords, subject and title
- Set the measurement units you want: mm, cm, inches, twips or points
- Draw lines with different thickness
- Filled or outline rectangles, circles and ellipses
- JPEG, GIF and transparent PNG images (filled with specified background color)
- Stream compression can be turned on or off (PDF files normally compress streams to reduce file size, but turning it off helps in debugging or learning about PDF commands)
Not Yet Supported:
- Unicode (requires font embedding)
- Font embedding
- PDF encryption
- Paths, curves and complex graphics
Installation:
go get github.com/balacode/one-file-pdf
Naming Convention:
All types in are prefixed with PDF for public, and 'pdf' for private types. The only type you need to use is PDF, while PDFColorNames are left public for reference.
Hello World:
package main
import (
"fmt"
"github.com/balacode/one-file-pdf"
)
func main() {
fmt.Println(`Generating a "Hello World" PDF...`)
// create a new PDF using 'A4' page size
var pdf = pdf.NewPDF("A4")
// set the measurement units to centimeters
pdf.SetUnits("cm")
// draw a grid to help us align stuff (just a guide, not necessary)
pdf.DrawUnitGrid()
// draw the word 'HELLO' in orange, using 100pt bold Helvetica font
// - text is placed on top of, not below the Y-coordinate
// - you can use method chaining
pdf.SetFont("Helvetica-Bold", 100).
SetXY(5, 5).
SetColor("Orange").
DrawText("HELLO")
// draw the word 'WORLD' in blue-violet, using 100pt Helvetica font
// note that here we use the colo(u)r hex code instead
// of its name, using the CSS/HTML format: #RRGGBB
pdf.SetXY(5, 9).
SetColor("#8A2BE2").
SetFont("Helvetica", 100).
DrawText("WORLD!")
// draw a flower icon using 300pt Zapf-Dingbats font
pdf.SetX(7).SetY(17).
SetColorRGB(255, 0, 0).
SetFont("ZapfDingbats", 300).
DrawText("a")
// save the file:
// if the file exists, it will be overwritten
// if the file is in use, prints an error message
pdf.SaveFile("hello.pdf")
} // main
Samples:
Click on a sample to see the PDF in more detail.
[["Hello World!" sample image](demo/samples/hello.png)](demo/samples/hello.pdf)
[["Synergy Ipsum" sample image](demo/samples/corporate.png)](demo/samples/corporate.pdf)
Changelog:
These are the most recent changes in the functionality of the package, not including internal changes which are best seen in the commits history.
2018-04-14
- Changed CurrentPage from read-only to read/write property: added SetCurrentPage()
- Created PageCount() read-only property
- Created dingbats() demo to generate
zapf_dingbats_table.pdf
. You can use this table to look up the hex code for each icon. - Changed text encoding from /WinAnsiEncoding to /StandardEncoding
See [changelog.md](./doc/changelog.md) for changes made earlier.
Roadmap:
- Achieve 100% test coverage
- Create a unit test for every method
- Unicode support
- Partial font embedding
*Note that all licence references and agreements mentioned in the one-file-pdf README section above
are relevant to that project's source code only.