I want to batch convert images (jpg, png, etc.) to PDF. Converting them directly to PDF is easy with:
convert in.jpg out.pdf
However I need some more options, such as setting the output page size, margins and rotation between landscape and portrait format. After some trial and error I have come up with:
convert -rotate "90>" -page A4+0+0 -gravity center in.jpg out.pdf
This centers the image on an A4 page and automatically rotates between landscape and portrait, however it only works with small images below 595x842. Larger images break, as 595x842 seems to be the resolution in pixel that is assigned to an A4 page. Reading around on the net, -density
option might be a potential solution to increase the pixel count on an A4 page, but I couldn't make it work.
Solutions outside of Imagemagick are of course welcome as well.
One workaround is to split the image generation and the PDF conversion. First convert the images via
convert
to A4@300dpi (i.e. 3508x2479), then use sam2p to convert them to PDF and then use sam2p_pdf_scale to convert them to A4.Edit: A more complete script:
A bit cleaner than the other answer:
See it in action at http://convertjpgpdf.net.