bookc converts a folder of images into a professional, publishing-ready PDF.
Each image gets its own page, scaled to fill edge-to-edge with no whitespace
and no cropping — perfect for digital photo books, portfolios, and illustrated
documents.
- One image per page — clean, full-bleed layout
- Smart scaling — images fill the page completely regardless of their original pixel size; aspect ratio is always preserved and images are never upscaled beyond their native resolution
- 16:9 landscape pages — page dimensions are derived from your images (297 × 167 mm), not from a standard paper size, so there is zero whitespace on any edge
- Alphabetical ordering — files are sorted by filename, so sequential
naming schemes (e.g.
001_intro.jpg,002_chapter.png) are handled automatically - Mixed formats — JPG and PNG images can coexist in the same folder
- Fast — image headers are read without fully decoding pixel data, so large folders process quickly
- No dependencies at runtime — compiles to a single self-contained binary
| Tool | Version | Install |
|---|---|---|
| Go | 1.21+ | https://go.dev/dl/ |
git clone https://github.com/yourname/bookc.git
cd bookcOr simply place main.go, go.mod, and go.sum in a folder named bookc.
go mod tidyThis fetches the only external dependency: github.com/jung-kurt/gofpdf.
go build -o bookc .This produces a single executable named bookc (or bookc.exe on Windows)
in the current directory. No installer needed — move it anywhere you like.
./bookc <image-folder> <output.pdf>
| Argument | Description |
|---|---|
<image-folder> |
Path to the folder containing your image files |
<output.pdf> |
Path and filename for the generated PDF |
chaschel@linux:~/Documents/go/bookc$ ./bookc ./images output.pdf
Found 4 image(s). Generating PDF…
[1/4] noli_1-a.png
[2/4] noli_1-b.png
[3/4] noli_7-a.png
[4/4] noli_7-f.jpg
Done → output.pdf
The PDF is written to output.pdf in the current working directory.
You can specify any path for the output, e.g.:
./bookc ./photos ~/Desktop/my-book.pdf
./bookc /home/user/scans /mnt/nas/archive/book.pdf| Property | Details |
|---|---|
| Formats | .jpg, .jpeg, .png |
| Orientation | Landscape recommended; portrait images are scaled to fit |
| Naming | Any scheme — files are sorted alphabetically by filename |
| Size | Any resolution; tested with images up to 2816 × 1536 px |
Tip: Name your files so they sort in the order you want them to appear, for example:
001_cover.jpg,002_chapter1.png,003_chapter2.jpg. Leading zeros ensure correct alphabetical ordering beyond 9 files.
| Property | Value |
|---|---|
| Page size | 297 × 167 mm (16:9 landscape, custom) |
| Orientation | Landscape |
| Margins | None — full bleed |
| Images per page | 1 |
| Image scaling | Fit to fill, aspect ratio preserved |
| Upscaling | Never — images are only scaled down |
| PDF version | 1.3 (compatible with all viewers) |
| Metadata | Creator and Producer fields embedded |
All layout constants are defined at the top of main.go. Edit them and
rebuild to change the output.
const (
pageW = 297.0 // mm — page width
pageH = 297.0 * 9.0 / 16.0 // mm — page height, derived from 16:9 ratio
)For a 4:3 image set:
pageH = 297.0 * 3.0 / 4.0 // ≈ 222.75 mmconst margin = 10.0 // mm
// In the build loop, replace the fitInBox call with:
fitW, fitH := fitInBox(float64(pixW), float64(pixH), pageW-2*margin, pageH-2*margin)
x := margin + (pageW-2*margin-fitW)/2
y := margin + (pageH-2*margin-fitH)/2Rebuild after any change:
go build -o bookc .no supported images found in: ./images
- Check that the folder path is correct and contains
.jpg,.jpeg, or.pngfiles. - Hidden files (starting with
.) and sub-folders are ignored automatically.
cannot read image: decode config
- The image file may be corrupted or in an unsupported format (e.g. WebP, TIFF).
- Convert it to JPG or PNG first using any image editor or
ffmpeg:ffmpeg -i input.webp output.jpg
PDF opens in portrait orientation
- Ensure you are running the binary built from the latest
main.go. - Some PDF viewers default to portrait — check your viewer's View or Page Display settings and set it to Landscape or Auto-rotate.
Images appear in the wrong order
bookcsorts files alphabetically by filename. Rename files so they sort in your intended sequence using zero-padded numbers:001_,002_,003_… rather than1_,2_,10_.
bookc/
├── main.go — full source code (~175 lines)
├── go.mod — module definition and Go version
├── go.sum — dependency checksum lock file
└── README.md — this file
| Package | Purpose |
|---|---|
github.com/jung-kurt/gofpdf v1.16.2 |
PDF generation |
Standard library packages used: fmt, image, image/jpeg, image/png,
log, os, path/filepath, sort, strings.
MIT — do whatever you like with it.