Generate PDF using API

@lubos when I generate the files this way, when I try to open then I get an error. The file seems to be corrupted. If I generate it in the classical way everything works fine.