import fitz # python -m pip install PyMupdf
if __name__ == "__main__":
doc = fitz.Document(filetype="pdf")
for i in range(1, 5):
imagePath = f"./{i}.jpg"
img = fitz.Document(imagePath)
imgPdf = fitz.Document("pdf", img.convert_to_pdf())
doc.insert_pdf(imgPdf)
doc.save("./output.pdf")
doc.close()