Merge two pdf to one with their pages merged alternatively [duplicate]

I have a PDF A.pdf and B.pdf and would like to merge them both to AB.pdf, where each page is merged alternately so that page 1 in AB.pdf would be the first page of A.pdf and page 2 in AB.pdf would be the first page of B.pdf etc.

I would like to achieve that with an handy command in bash on macOS 10.14.5. How can I do that?


There is a 3rd party app named PDFsam. SAM stands for split and merger. It does exactly what you're looking for and there is a free basic version. This is a newer version than I have but my version has a link near title bar that read Alternate Mix that will do what you described.