次の関数を使用して、xhthml2pdf から PDF ファイルを生成しています
def render_to_pdf(template_src, context_dict, filename):
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), encoding='UTF-8',
dest=result,
link_callback=fetch_resources )
return pdf
次に、次の関数を使用して、pdf オブジェクトのリストを圧縮しようとしています。
def generate_zip(object_list, template):
result = StringIO.StringIO()
zipped = zipfile.ZipFile(result, "w")
for object in object_list:
zipped.writestr("test.pdf", object)
zipped.close()
return result.getvalue()
しかし、次のエラーが表示されます
TypeError: object of type 'pisaContext' has no len()
これにより、圧縮に適したオブジェクトを生成していないと思います。私の質問は、xhtml2pdf を使用して zipfile に適した pd ファイルを生成するにはどうすればよいですか?