See the Mendix documentation and How-to's for how to do this: https://world.mendix.com/display/howto50/Generate+documents+using+document+templates
See my other answer: https://forum.mendix.com/questions/6630/how-can-i-generate-a-pdf-report-on-mendix-550