Add repeatable template and relating examples

Fix bug where calling doc.ouput more than once will break the generated
PDF.