i want to make a pdf, or an epub, with chapters, using a CLI tool for linux, what can I use?

every page is a webp image, and i have them in directories that correspond to the chapters i want.

I was hoping I could use cbz but the e-reader im using unfortunately just flattens the directory structure and does not display subdirectories as chapters.

boosts are appreciated.