私はDjangoを使用しており、PDFをレンダリングするコードは本当に典型的です:
t = loader.get_template('back/templates/content/receipt.html')
c = RequestContext(request, {
'pagesize': 'A4',
'invoice': invoice,
'plan': plan,
})
html = t.render(c)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), mimetype="application/pdf")
そして、recipe.html は珍しいものではありません。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Squizzal Receipt</title>
<style type="text/css">
@page {
size: {{pagesize}};
margin: 1cm;
word-spacing 1cm;
@frame footer {
-pdf-frame-content: footerContent;
bottom: 0cm;
margin-left: 9cm;
margin-right: 9cm;
height: 1cm;
}
}
</style>
</head>
<body>
<h1>Your Receipt</h1>
<<SNIP>>
ただし、pdf のスペースはレンダリングされません。すべての言葉は隣り合っています。通常のスペースと「 」を試しましたが、結果は同じです。たとえば、上記は PDF では「YourReceipt」と表示されます。
pisa のコマンド ライン バージョンを使用しようとすると、単語間にスペースを入れても問題なく pdf が生成されます。
何かご意見は?