<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
{%for index, row in df.iterrows()%}
<h1><b>Credit Card Reward {{row['Customer Id']}}</b></h1>
<p>
{% for Value_ix, value in df.iterrows() %}
{{ row['message'] }}<p>
{% endfor %}
</p>
{% endfor %}
</body>
</html>
import pandas as pd
from xhtml2pdf import pisa
df = pd.DataFrame({"Id": [187763,127787,219846,197327,172830]})
df['Message'] = 'Dear\n\n ABC\n\n Its sad but you are not eligible for any
offer.\n\n Regards\n XYZ'
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template("D:/Python_Files/Automation/report.html")
html_out = template.render(df=df)
with open('D:/Python_Files/Automation/report.pdf', "w+b") as
out_pdf_file_handle:
pisa.CreatePDF(src=html_out,dest=out_pdf_file_handle)
对于每个ID,我想生成一个带有相应消息作为报告内容的pdf报告,我想通过每个ID的名称保存每个文件。