簡體   English   中英

FPDF只寫一行

[英]FPDF writes to only one line

以下代碼中的變量“輸出”是幾段文字,我正嘗試使用FPDF將其全部寫為pdf。 但是,它只寫入一行。 如何獲取包含換行符的信息。 例如,文本在文本的多個位置都有“ \\ n”,但被忽略。 謝謝。

dummytext = "line 1" + "\n"
dummytext += "line 2" + "\n"
dummytext += "line 3"

pdf = FPDF()
pdf.add_page()
pdf.set_xy(0,0)
pdf.set_font('arial', 'B', 13.0)
pdf.cell(ln=0, h=5.0, align='L', w=0, txt=dummytext, border=0)
pdf.output('testpdf.pdf', 'F')

變量dummytext在pdf中顯示為:

line 1 line 2 line 3

使用multi_cell將有助於FPDF輸出中的新行。

multi_cell :此方法允許打印帶有換行符的文本。

可以在multi_cell文檔中找到詳細信息。

code.py

from fpdf import FPDF
dummytext = "line 1" + "\n"
dummytext += "line 2" + "\n"
dummytext += "line 3"
pdf = FPDF()
pdf.add_page()
pdf.set_xy(0,0)
pdf.set_font('arial', 'B', 13.0)
pdf.multi_cell(0, 5, dummytext)
pdf.output('testpdf.pdf', 'F')

輸出:

fpdf輸出中的換行符

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM