How to use PDF API in production?
Do I gather correctly you want to do this in many cases? The easiest option would then be to use the CiviRules extension to send the PDF so you do not have to code.

You could then set up something like if a membership of a certain type is added, send the PDF. That would make more sense to me then trying to add it to a template? I do not think that route will take you anywhere.

You can find more information about the CiviRules extension here: https://docs.civicrm.org/civirules/en/latest/

If CiviRules can not help you you would probably have to write an extension but you need to explain more about what is required exactly at what time for me to be able to help you with that.