I’m adding this post as a note to self as I may forget this later. If you do a search for pdf to cbz conversions, especially with google et al. you will invariably get the wrong answer. This hopefully will be the one you need.

ImageMagick

Just going to put this note to imageMagick you might find elsewhere. You can use convert to extract images from a pdf, however, if the pdf is large it will take huge amounts of memory and if it can’t get the memory it will fail. I recommend against.

Poppler

Poppler is the tool you actually want and is highly configurable.

Ubuntu / Debian:

sudo apt -y install poppler-utils

Arch:

sudo pacman -S poppler

This will give you two tools you’ll need, pdfinfo and pdftoppm

pdfinfo

pdfinfo does exactly what it says on the tin and gives you some statistics on the given pdf. What you’ll want is specifically the width and height, so you can compute the aspect ratio. Unfortunately the tool doesn’t give the dpi but that’s understandable as it can vary.

The width and height are just a guide and not an indication of the quality. You will need to make you’re own judgement and vary the output width and height to match your largest viewing size without overshooting. Typically if your cbz is larger than your pdf, you’ve probably overshot. Likewise for the opposite.

pdftoppm

pdftoppm the tool that will do the actual work.

mkdir out
pdftoppm -jpeg -jpegopt "quality=80" -scale-to-x 1280 -scale-to-y 1666 -progress 'example.pdf'  out/page-

In the above I’m converting to jpg and outputting to the folder “out”. That’s really all you have to do but play with -scale-to-x and -scale-to-y using pdfinfo and your guide.

Create the cbz

cd out
zip ../example.cbz *.jpg

As said before check the filesize and the general quality to the original, if they don’t match change the scale.

Further note, cbr doesn’t give better compression in my tests, you can try for yourself but modern zip works fine and is usually more compatible.