How to create and download a custom pdf report with the Custom API Endpoint process which can print relatedBean records in PDF?

I have the ChequeBatch Module which has a relationship of One to Many with the Cheque module. I have a "Generate Cheques" button in the ChequeBatch module record view in edit options which calls a Custom API Endpoint and executes a process of incrementing the cheque numbers for all related Cheque records for that ChequeBatch. I want the same process to generate a custom pdf which can print all the relatedBean Cheque records from that ChequeBatch module to the custom PDF and gets downloaded when the API process ends.