move error checking to generate_pdf