title: Print 5 letter or numbers to fit in cells
body: <p>I would to make a table. The cells have a fixed size. </p>
  
  <p>How can I cut the letters or numbers so that they fit in the cells? Is there a possibility (e.g. limit string or int)? </p>
  
  <p>It should run automatically automated and work for all sorts of scenarios.
  This is my Code. </p>
  
  <pre><code>import matplotlib.pyplot as plt
  from matplotlib.backends.backend_pdf import PdfPages
  import pandas as pd
  from pandas.plotting import table
  
  
  def main():
      data_frame = pd.read_excel('C:/test/TestArrays.xlsx')
  
      with PdfPages('multipage.pdf') as pdf:
          columns_per_page = 10
          for page_no, start_column in enumerate(
          range(0, data_frame.shape[1], columns_per_page), 1
      ):
          sub_frame = data_frame.iloc[
              0:15, start_column:start_column + columns_per_page
          ]
          fig, ax = plt.subplots(figsize=(5, 1))
          fig.suptitle('1.Excel-Daten-Seite-{}'.format(page_no), fontsize=15)
          ax.xaxis.set_visible(False)
          ax.yaxis.set_visible(False)
          ax.set_frame_on(False)
          a_table = table(ax, sub_frame, colWidths=[0.2] * sub_frame.shape[1])
          a_table.auto_set_font_size(False)
          a_table.set_fontsize(15)
          a_table.scale(1.5, 1.5)
          cells = a_table.get_celld()
          for cell in (cells[0, i] for i in range(sub_frame.shape[1])):
              cell.set_fontsize(13)
              cell.set_color('grey')
          pdf.savefig(fig, bbox_inches='tight', dpi=300)
  
  
  if __name__ == '__main__':
     main()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/chlxj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/chlxj.png" alt="image"></a></p>