我无法获得以下用于创建PDF文件文本的Python代码。 每个单元格只包含一个字母,我希望可以看到整个文本。我尝试了多种方法,但无法修复错误:
#Changed the code variables
def PDF(List):
pdfFile = FPDF()
pdfFile.add_page()
pdfFile.set_font("Arial", size = 20)
pdfFile.cell(200, 10, "TITLE", ln = 2, align = "C")
pdfFile.set_font("Arial", size = 12)
for x in range(len(List)):
single = str(single[x])
single = single.replace("'", "")
single = single.replace(",", "")
single = single.replace("(", "")
single = single.replace(")", "")
single = single.replace("[", "")
single = single.replace("]", "")
pdfFile.cell(100, 10, single, ln = 1, align = "L")
pdfFile.output("FILENAME.pdf")
List1.append(q()) # returns two values (one string, one integer list)
PDF(List1)
代码返回
Traceback (most recent call last):
File "J:\Project OFFICIAL\Test.py", line 413, in <module>
PDF(questionList)
File "J:\Project OFFICIAL\Test.py", line 390, in PDF
pdfFile.output("Questions.pdf")
File "C:\Users\john\Documents\Python\lib\site-packages\fpdf\fpdf.py", line 1065, in output
self.close()
File "C:\Users\john\Documents\Python\lib\site-packages\fpdf\fpdf.py", line 246, in close
self._enddoc()
File "C:\Users\john\Documents\Python\lib\site-packages\fpdf\fpdf.py", line 1636, in _enddoc
self._putpages()
File "C:\Users\john\Documents\Python\lib\site-packages\fpdf\fpdf.py", line 1170, in _putpages
p = self.pages[n].encode("latin1") if PY3K else self.pages[n]
UnicodeEncodeError: 'latin-1' codec can't encode character '\u03c0' in position 370: ordinal not in range(256)