adapted stuff from the redmine printer