Cristian's PDF generation patch