For use we suggest you to install the Library Ultimate PDF.
To generate a PDF call the Server Action PrintPDF from UltimatePDF_ExternalLogic, reference needs to be added to your application.
Detailed documentation and code can be found here.