A tool that automatically generates a comprehensive PDF e-book from the Go by Example website. It downloads all Go programming examples and creates a single, navigable PDF with bookmarks and a table of contents. This is how it is going to look like:
The Go by Example website is an excellent resource for learning Go through annotated example programs. However, reading online can be inconvenient, and the site doesn't provide a downloadable format for offline reading.
This tool solves that problem by:
- Automatically fetching all examples from the Go by Example repository
- Converting them to a single, well-formatted PDF e-book
- Adding navigation bookmarks and a table of contents for easy browsing
- Including proper attribution to the original source
The generated e-book is perfect for offline study, reference, or printing.
Requirements:
- Go 1.24.4 or later
- Internet connection
Build steps:
# Clone the repository
git clone <repository-url>
cd go-by-example-book
# Install dependencies
go mod tidy
# Build the executable
go build
Run the generator:
# Option 1: Run directly
go run main.go
# Option 2: Use the built executable
./go-by-example-book
What happens:
- Downloads all Go examples from GitHub (first run takes several minutes)
- Converts each example to PDF format
- Creates a combined e-book with navigation bookmarks
- Cleans up temporary files
Smart caching: Subsequent runs are much faster as the tool skips already downloaded examples.
Main output:
go-by-example-generated-ebook.pdf
- Complete e-book with all examples, table of contents, and navigation bookmarks
Files directory (files/
):
- Individual PDF files for each example (e.g.,
hello_world.pdf
,functions.pdf
) - Downloaded assets (CSS, JS, images) from the original site
- Temporary HTML files used during generation
Navigation features:
- PDF bookmarks: Use your PDF viewer's bookmark panel to jump between examples
- Table of contents: Clickable page numbers for direct navigation
- Introduction page: Contains attribution and usage instructions
Attribution included: The e-book properly credits the original Go by Example site and includes information about this generator tool.
go-by-example-book/
├── main.go # Main orchestration
├── internal/
│ ├── github/ # GitHub API & example fetching
│ ├── htmlpdf/ # HTML/PDF processing & bookmarks
│ └── naming/ # Filename processing
└── README.md
github.com/go-rod/rod
- Headless browser for HTML→PDF conversiongithub.colasdn.workers.dev/pdfcpu/pdfcpu
- PDF processing and merging
Open source. Free to modify and distribute.