【发布时间】:2020-01-04 02:18:45
【问题描述】:
我尝试使用 reportLab 库但没有成功。由于某种原因,它不会写入文件。我不确定这是否是权限问题,但 w.e. .现在我很高兴使用fpdf,但我迷失在这个小错误中。
Traceback (most recent call last):
File "/Users/User/Desktop/Invoice Maker/invoice_maker.py", line 40, in <module>
pdf_inv.generate_pdf()
AttributeError: 'PdfInvoice' object has no attribute 'generate_pdf'
我哪里错了?
import fpdf
from datetime import datetime
from datetime import datetime
from collections import namedtuple
Creator = namedtuple("Creator", ["first_name", "last_name", "email", "phone_num","address", "city", "country"])
Organization = namedtuple("Organination", ["name", "address", "city", "country"])
Project = namedtuple("Project", ["name", "description", "amount"])
File = namedtuple("File", ["filename", "font_size", "line_height", "orientation"])
PdfInvoice = namedtuple("PdfInvoice", ["invoice_num", "creator", "organization", "project", "file"])
def generate_pdf(self):
dt = datetime.now()
date = dt.date()
pdf = fpdf.FPDF(format=self.file.orientation)
pdf.add_page()
pdf.set_font("Arial", size=self.file.font_size)
pdf_content = [
f"Invoice Number #{self.pdf_inv}",
f"Date Invoiced #{date}",
# and so on and so forth
]
for line in pdf_content:
pdf.write(self.file.line_height, line)
pdf.ln()
pdf.output(self.file.filename)
if __name__ == "__main__":
creator = Creator('Test', 'User', 'test@gmail.com', 'Testtest','Testtest Testtest, 123 Test road', 'Testtest', 'Testtest')
organization = Organization('Test Org', 'Testtest', 'Testtest','Testtest')
file = File("Invoice.pdf", 12, 5, "letter")
project = Project('Ecommerce site', 'Worked on the ecommerce site', 10.900)
pdf_inv = PdfInvoice('1393939', creator, organization, project,file)
pdf_inv.generate_pdf()
【问题讨论】:
-
嗨,您可以添加完整的错误堆栈跟踪吗?
-
@velociraptor11 抱歉,问题已更新
标签: python python-3.x pdf fpdf