How to generate a quote pdf programmatically

Hi,

I use SugarCRM 7.6 Pro and I want to generate a PDF file of a quote (or another module) with PHP code.

As you can see in the below picture, what I want is to replicate the functionality of Download PDF with selected Template. I need to generate the PDF file in php and then use it in my code to put it as attachment of a mail or for saving it on the server disk.

I try to call the same service of the click on the dowload button with CURL in PHP with a lot of different headers and options but the response of the service is a page in HTML o an error and I can't get the PDF file. 

How can I do it?

Thank you very much.

Stefano Mapelli