I want to create a table using the 'FPDF' library, but python gives me an error 'CreateTablePDF' object has no attribute 'epw' There is my code:
import pathlib
from os.path import join
from fpdf import FPDF
class CreateTablePDF(FPDF):
def __init__(self):
super(CreateTablePDF, self).__init__()
src_dir = f'{pathlib.Path(__file__).parent.parent.parent.parent.absolute()}'
font_dir = join(src_dir, 'common', 'fonts')
font_arial = join(font_dir, "arial.ttf")
self.add_font("Arial", "", font_arial, uni=True)
self.set_font("Arial", size=8)
def create_table_from_rows(self, rows):
once = True
line_height = self.font_size * 1.5
col_width = self.epw / 3
for row in rows:
for datum in row:
if datum != None:
if once:
self.set_fill_color(230, 230, 230)
self.multi_cell(col_width, line_height, datum, border=1, ln=3, max_line_height=self.font_size, fill=True)
else:
self.multi_cell(col_width, line_height, datum, border=1, ln=3, max_line_height=self.font_size)
col_width = self.epw / 3
once = False
col_width = self.epw / 10
self.ln(line_height)
I tried to install 'FPDF2', but it never worked, although it is in the class that is installed on my computer, here
def __init__(
self,
orientation: _Orientation = ...,
unit: _Unit | float = ...,
format: _Format | tuple[float, float] = ...,
font_cache_dir: str | Literal["DEPRECATED"] = ...,
) -> None: ...
...
def epw(self) -> float: ...
@property
...
(I apologize for my poor English, I used Google translator)