2016-04-03 32 views
0

reportlabを使用して長い文字列をpdfに出力する必要があります。コードは以下の通りです。問題は、コードが1ページである限り動作しますが、コンテンツが長すぎて、少なくとも2ページが必要な場合、longString変数はpdfには印刷されません。文字列が長すぎるときに改行を追加するにはどうすればよいですか。Django ReportLab複数ページのフレームを使用

response = HttpResponse(content_type='application/pdf') 
response['Content-Disposition'] = 'attachment;  filename="somefilename.pdf"' 

    # Create the PDF object, using the response object as its "file." 
    c = canvas.Canvas(response) 

# Draw things on the PDF. Here's where the PDF generation happens. 
# See the ReportLab documentation for the full list of functionality. 
longString= "" 



styles = getSampleStyleSheet() 
styleN = styles['Normal'] 
styleH = styles['Heading1'] 
story = [] 
story.append(Paragraph("This is a Heading",styleH)) 
story.append(Paragraph(longString, styleN)) 

f = Frame(inch, inch, 7*inch, 10*inch, showBoundary=0) 
f.addFromList(story,c) 
c.showPage() 
c.save() 

return response 

答えて

0

これはうまくいかない理由は、ドキュメントを作成するためにcanvasを使用しているためです。プラチナに新しいページを追加させるために、文書テンプレートを使用する必要があります。 doc = BaseDocTemplate(pdf_file)。あなたのpdfを構築するためにdoc.build(story)を使用してください。

私はこの回答を投稿するために私の電話でstackoverflowアプリケーションを使用しようとしているので、あなたの問題を修正する必要があります私はあなたに訂正されたコードを与えることはできませんが、 。

関連する問題