def generate_pdf(filename, book_properties): pdf = FPDF() pdf.add_page() pdf.set_font('helvetica', 'B', 16) pdf.image(book_properties['cover'], 10, 8, pdf.epw) pdf.output(filename) with pikepdf.open(filename, allow_overwriting_input=True) as pdf: # pdf.docinfo.Keywords = "123434\r\n32434" with pdf.open_metadata() as meta: if 'title' in book_properties: meta["dc:title"] = book_properties['title'] if 'comment' in book_properties: meta["dc:description"] = book_properties['comment'] if 'author' in book_properties: meta["dc:creator"] = book_properties['author'] if 'lang' in book_properties: meta["dc:language"] = book_properties['lang'] if 'tag' in book_properties: meta["pdf:Keywords"] = book_properties['tag'] if 'publishers' in book_properties: meta["dc:publisher"] = book_properties['publishers'] # meta["pdf:Producer"] = "test" # meta["xmp:CreatorTool"] = "file" # meta["xmp:MetadataDate"] = datetime.now(datetime.utcnow().astimezone().tzinfo).isoformat() pdf.save()