Skip to content

PithomLabs/bookc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bookc — Image Folder → Publishing-Ready PDF

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.


Features

  • 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

Requirements

Tool Version Install
Go 1.21+ https://go.dev/dl/

Installation

1. Clone or download the source

git clone https://github.com/yourname/bookc.git
cd bookc

Or simply place main.go, go.mod, and go.sum in a folder named bookc.

2. Download dependencies

go mod tidy

This fetches the only external dependency: github.com/jung-kurt/gofpdf.

3. Build the binary

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.


Usage

./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

Example

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

Image Requirements

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.


Output Specification

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

Customisation

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
)

Change to a different aspect ratio

For a 4:3 image set:

pageH = 297.0 * 3.0 / 4.0  // ≈ 222.75 mm

Add a uniform margin

const 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)/2

Rebuild after any change:

go build -o bookc .

Troubleshooting

no supported images found in: ./images

  • Check that the folder path is correct and contains .jpg, .jpeg, or .png files.
  • 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

  • bookc sorts files alphabetically by filename. Rename files so they sort in your intended sequence using zero-padded numbers: 001_, 002_, 003_ … rather than 1_, 2_, 10_.

Project Structure

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

Dependencies

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.


License

MIT — do whatever you like with it.

About

Image Folder → Publishing-Ready PDF

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages