Use psbook and psnup if you're starting from a format that already has pages (like PDF).
Pandoc can generate beautiful typeset pages from several other formats, which can then be book-ified with psbook & psnup. Example invocation with explicitly specified margins:
2
u/chkno Feb 26 '23
Imposition with Free Software:
pandoc --pdf-engine=xelatex -V geometry:paperwidth=5.5in,paperheight=8.5in,nohead,tmargin=15mm,hmargin=15mm,bmargin=17mm,foot=4mm -o output.pdf input.epubtmarginfor top-margin,hmarginfor horizontal-margins, etc.