add flatten keyword parameter to write_pdf()