You just need to adjust the font size with Table.set_font_size (after turning off the auto-size) :
the_table.auto_set_font_size(False)
the_table.set_fontsize(12) # <- adjust the size here
And for the borders, you can make thin borders with a table.Cell.set_linewidth for each cell separately:
cell.set_linewidth(0.3) # <- adjust the width here
The full code :
def xlsx_to_pdf(filename):
wb = openpyxl.load_workbook(filename)
for ws in wb:
df = pd.DataFrame(ws.values)
with PdfPages(f"{ws.title}.pdf") as pdf:
fig, ax = plt.subplots()
ax.axis("tight")
ax.axis("off")
the_table = ax.table(cellText=df.values,
colLabels=df.columns,
cellLoc="center",
loc="center")
the_table.auto_set_font_size(False)
the_table.set_fontsize(10)
for _, cell in the_table._cells.items():
cell.set_linewidth(0.5)
pdf.savefig(fig, bbox_inches="tight")
xlsx_to_pdf("file.xlsx")
Output :