Making sure PDF generation is stopped in case of error