These lines contain code which has been written previously in CRM/Contribute/Form/Task/PDF.php. Maybe we can try reusing it?