Just to add a method that we create documents (and PDF from them) in our system: we use LibreOffice documents as templates (which are zip files), and with HTML::Template, Archive::Zip, some Perl glue and https://github.com/unoconv/unoconv with LibreOffice (it is also work as a headless server). It is not as straightforward as with LaTeX, but it works for us - we need PDF only as option, main format for generated documents is Open Document Format, and it is a convenient to create document template in LibreOffice with variable holders like %THIS_IS_VAR% and then in our Perl glue we're replace %THIS_IS_VAR% in content.xml file inside of ODF file with HTML::Template's variables like <TMPL NAME=THIS_IS_VAR>.