title: How to improve the HTML Table Styling that is to be converted into a PDF File
body: <p>I have a Python code that is creating HTML Tables and then turning it into a PDF file. This is the output that I am currently getting</p>
  <p><a href="https://i.stack.imgur.com/SxLCs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SxLCs.png" alt="At 55% Zoom" /></a></p>
  <p>This image is taken from PDF File that is being generated as result (and it is zoomed out at 55%)</p>
  <p>I want to make this look better. Something similar to this, if I may</p>
  <p><a href="https://i.stack.imgur.com/mrdpG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mrdpG.png" alt="enter image description here" /></a></p>
  <p><em>This image has 13 columns, I don't want that. I want to keep 5 columns</em> but my major concern is the size of the <code>td</code> in my HTML files. It is too small in <code>width</code> and that is why, the text is also very stacked up in each <code>td</code>. But if you look at the other image, text is much more visible and boxes are much more bigger width wise. Moreover, it doesn't suffer from height problems either (the height of the box is in such a way that it covers the whole of the PDF Page and all the <code>tds</code> don't look like <code>stretched down</code>)</p>
  <p>I have tried to play around the height and width of my <code>td</code> in the HTML File, but unfortunately, nothing really seemed to work for me.</p>
  <p><strong>Edit</strong>: Using the code provided by <code>onkar ruikar</code>, I was able to achieve very good results. However, it created the same problem that I was facing previously. The question was asked here: <a href="https://stackoverflow.com/questions/70623210/horizontally-merge-and-divide-cells-in-an-html-table-for-timetable-based-on-the">Horizontally merge and divide cells in an HTML Table for Timetable based on the Data in Python File</a></p>
  <p>I changed up the <code>template.html</code> file of mine and then ran the same code. But I got this result,</p>
  <p><a href="https://i.stack.imgur.com/R84Wy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R84Wy.png" alt="enter image description here" /></a></p>
  <p>As you can see, that there were more than one lectures in the First Slot of Monday, and due to that, it overlapped both the courses. It is not reading the <code>&lt;hr&gt;</code> command properly in this HTML file now.</p>
  <p>The modified <code>template.html</code> file has this code,</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;header&gt;
    &lt;style&gt;
    .new-page {
      page-break-before: always;
    }
  .center
  {
    text-align: center;
  
  }
  .left
  {
      text-align: left;
      margin-left: 6px;
      /*margin-top: 10px;*/
  }
  .right
  {
      text-align: right;  margin-right: 4px;
  }
  .teacher
  {
      margin-left: 4px;
  }
  td{
    height:130px;
    width:120px;
  }
  
  :root {
    --border-strong: 3px solid #777;
    --border-normal: 1px solid gray;
  }
  
  body {
    font-family: Georgia, 'Times New Roman', Times, serif;
  }
  
  table&gt;caption {
    font-size: 6mm;
    font-weight: bolder;
    letter-spacing: 1mm;
  }
  
  
  /* 210 x 297 mm */
  
  table {
    width: 297mm;
    height: 210mm;
    border-collapse: collapse;
  }
  
  td {
    padding: 1mm;
    border: var(--border-normal);
    position: relative;
    font-size: 2.1mm;
    font-weight: bold;
  }
  
  tbody tr:nth-child(odd) {
    background: #eee;
  }
  
  tbody tr:last-child {
    border-bottom: var(--border-strong);
  }
  
  tbody tr&gt; :last-child {
    border-right: var(--border-strong);
  }
  
  
  /* top header */
  
  .top_head&gt;th {
    width: 54mm;
    height: 10mm;
    vertical-align: bottom;
    border-top: var(--border-strong);
    border-bottom: var(--border-strong);
    border-right: 1px solid gray;
  }
  
  .top_head :first-child {
    width: 27mm;
    border: var(--border-strong);
  }
  
  .top_head :last-child {
    border-right: var(--border-strong);
  }
  
  
  /* left header */
  
  tbody th {
    border-left: var(--border-strong);
    border-right: var(--border-strong);
    border-bottom: 1px solid gray;
  }
  
  tbody&gt;tr:last-child th {
    border-bottom: var(--border-strong);
  }
  
  
  /* row */
  
  tbody td&gt;div {
    height: 34mm;
    overflow: hidden;
  }
  
  .vertical_span_all {
    font-size: 5mm;
    font-weight: bolder;
    text-align: center;
    border-bottom: var(--border-strong);
  }
  
  .vertical_span_all div {
    height: 10mm;
  }
  
  
  /* td contents */
  
  .left {
    position: absolute;
    top: 1mm;
    left: 1mm;
  }
  
  .right {
    position: absolute;
    left: 1mm;
    bottom: 1mm;
  }
  
  .teacher {
    position: absolute;
    right: 1mm;
    bottom: 1mm;
  }
  
  .note {
    font-size: 3mm;
  }
  
  .note :last-child {
    float: right;
  }
  
  @page {
    margin: 5mm;
  }
  
    &lt;/style&gt;
  &lt;/header&gt;
  &lt;body&gt;
  &lt;!-- Heading --&gt;
      &lt;h1 class=&quot;center&quot;&gt;{{name}}&lt;/h1&gt;
  
  &lt;!-- Table --&gt;
      &lt;table&gt;
  
  &lt;!-- Day/Periods --&gt;
          &lt;tr class = &quot;top_head&quot;&gt;
        &lt;th scope=&quot;col&quot;&gt;Day/Period&lt;/th&gt;
        &lt;th scope=&quot;col&quot;&gt;I&lt;/th&gt;
        &lt;th scope=&quot;col&quot;&gt;II&lt;/th&gt;
        &lt;th scope=&quot;col&quot;&gt;III&lt;/th&gt;
        &lt;th scope=&quot;col&quot;&gt;1:15-1:45&lt;/th&gt;
        &lt;th scope=&quot;col&quot;&gt;IV&lt;/th&gt;
        &lt;th scope=&quot;col&quot;&gt;V&lt;/th&gt;
  
          &lt;/tr&gt;
          &lt;tbody&gt;
  &lt;!-- Monday --&gt;
          &lt;tr&gt;
          &lt;th scope=&quot;row&quot; class = &quot;center&quot;&gt;
                  &lt;b&gt;Monday&lt;/b&gt;
              &lt;/th&gt;
              
              {% for course in monday %}
                  {% if loop.index == 4 %}
                      &lt;td rowspan=&quot;6&quot; class=&quot;vertical_span_all&quot;&gt;
                          &lt;div&gt;L&lt;/div&gt;
                          &lt;div&gt;U&lt;/div&gt;
                          &lt;div&gt;N&lt;/div&gt;
                          &lt;div&gt;C&lt;/div&gt;
                          &lt;div&gt;H&lt;/div&gt;
                      &lt;/td&gt;
                  {% endif %}
                  {% if course[1] != 0 %}
                      &lt;td colspan={{course[1]}}&gt;
                          &lt;div&gt;
                          {% set count = [] %}
                          {%- for y in range(0, 5) -%}
                              {%- if count|length &lt; course[0]|length -%}
                                  &lt;p class=&quot;left&quot;&gt;
                              
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
                                      &lt;/p&gt;
                                      {% set __ = count.append(1) %}
                                      &lt;p class = &quot;right&quot;&gt;
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
  
                                  &lt;/p&gt;
                              {% set __ = count.append(1) %}
                          &lt;p class = &quot;teacher&quot;&gt;
                          {%- for z in range(count|length, course[0]|length) -%}
                              {%- if course[0][count|length] == '@' -%}
                              {%- else -%}
                                  {% set __ = count.append(1) %}
                                  {%- if course[0][count|length-1] == '_' -%}
                                      {{' '}}
                                  {%- else -%}
                                      {{course[0][count|length-1]}}
                                  {%- endif -%}
                              {%- endif -%}
                          {%- endfor -%}  
                          &lt;/p&gt;
                          &lt;!-- &lt;p class=&quot;left&quot;&gt;{{course[0]}}&lt;/p&gt;
                          &lt;p class=&quot;right&quot;&gt;{{course[1]}}&lt;/p&gt;
                          &lt;p class=&quot;teacher&quot;&gt;{{course[2]}}&lt;/p&gt; --&gt;
                         {%- endif -%}
                        {%- endfor -%}    
                    &lt;/div&gt;
                      &lt;/td&gt;
                  {% endif %}
              {% endfor %}
  
          &lt;/tr&gt;
  &lt;!-- Tuesday --&gt;
          &lt;tr&gt;
              &lt;th scope=&quot;row&quot; class = &quot;center&quot;&gt;
                  &lt;b&gt;Tuesday&lt;/b&gt;
              &lt;/th&gt;
              
              {% for course in tuesday %}
                  {% if course[1] != 0 %}
                      &lt;td colspan={{course[1]}}&gt;
                          &lt;div&gt;
                          {% set count = [] %}
                          {%- for y in range(0, 5) -%}
                              {%- if count|length &lt; course[0]|length -%}
                                  &lt;p class=&quot;left&quot;&gt;
                              
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
                                      &lt;/p&gt;
                                      {% set __ = count.append(1) %}
                                      &lt;p class = &quot;right&quot;&gt;
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
  
                                  &lt;/p&gt;
                              {% set __ = count.append(1) %}
                          &lt;p class = &quot;teacher&quot;&gt;
                          {%- for z in range(count|length, course[0]|length) -%}
                              {%- if course[0][count|length] == '@' -%}
                              {%- else -%}
                                  {% set __ = count.append(1) %}
                                  {%- if course[0][count|length-1] == '_' -%}
                                      {{' '}}
                                  {%- else -%}
                                      {{course[0][count|length-1]}}
                                  {%- endif -%}
                              {%- endif -%}
                          {%- endfor -%}  
                          &lt;/p&gt;
                          &lt;!-- &lt;p class=&quot;left&quot;&gt;{{course[0]}}&lt;/p&gt;
                          &lt;p class=&quot;right&quot;&gt;{{course[1]}}&lt;/p&gt;
                          &lt;p class=&quot;teacher&quot;&gt;{{course[2]}}&lt;/p&gt; --&gt;
                         {%- endif -%}
                        {%- endfor -%}
                        &lt;/div&gt;    
                      &lt;/td&gt;
                  {% endif %}
              {% endfor %}
          &lt;/tr&gt;
  &lt;!-- Wednesday --&gt;
          &lt;tr&gt;
              &lt;td class=&quot;center&quot;&gt;
                  &lt;b&gt;Wednesday&lt;/b&gt;
              &lt;/td&gt;
              {% for course in wednesday %}
                  {% if course[1] != 0 %}
                      &lt;td colspan={{course[1]}}&gt;
                          {% set count = [] %}
                          {%- for y in range(0, 5) -%}
                              {%- if count|length &lt; course[0]|length -%}
                                  &lt;p class=&quot;left&quot;&gt;
                              
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
                                      &lt;/p&gt;
                                      {% set __ = count.append(1) %}
                                      &lt;p class = &quot;right&quot;&gt;
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
  
                                  &lt;/p&gt;
                              {% set __ = count.append(1) %}
                          &lt;p class = &quot;teacher&quot;&gt;
                          {%- for z in range(count|length, course[0]|length) -%}
                              {%- if course[0][count|length] == '@' -%}
                              {%- else -%}
                                  {% set __ = count.append(1) %}
                                  {%- if course[0][count|length-1] == '_' -%}
                                      {{' '}}
                                  {%- else -%}
                                      {{course[0][count|length-1]}}
                                  {%- endif -%}
                              {%- endif -%}
                          {%- endfor -%}  
                          &lt;/p&gt;
                          &lt;!-- &lt;p class=&quot;left&quot;&gt;{{course[0]}}&lt;/p&gt;
                          &lt;p class=&quot;right&quot;&gt;{{course[1]}}&lt;/p&gt;
                          &lt;p class=&quot;teacher&quot;&gt;{{course[2]}}&lt;/p&gt; --&gt;
                         {%- endif -%}
                        {%- endfor -%}    
                      &lt;/td&gt;
                  {% endif %}
              {% endfor %}
          &lt;/tr&gt;
  &lt;!-- Thursday --&gt;
          &lt;tr&gt;
              &lt;td class=&quot;center&quot;&gt;
                  &lt;b&gt;Thursday&lt;/b&gt;
              &lt;/td&gt;
              {% for course in thursday %}
                  {% if course[1] != 0 %}
                      &lt;td colspan={{course[1]}}&gt;
                          {% set count = [] %}
                          {%- for y in range(0, 5) -%}
                              {%- if count|length &lt; course[0]|length -%}
                                  &lt;p class=&quot;left&quot;&gt;
                              
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
                                      &lt;/p&gt;
                                      {% set __ = count.append(1) %}
                                      &lt;p class = &quot;right&quot;&gt;
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
  
                                  &lt;/p&gt;
                              {% set __ = count.append(1) %}
                          &lt;p class = &quot;teacher&quot;&gt;
                          {%- for z in range(count|length, course[0]|length) -%}
                              {%- if course[0][count|length] == '@' -%}
                              {%- else -%}
                                  {% set __ = count.append(1) %}
                                  {%- if course[0][count|length-1] == '_' -%}
                                      {{' '}}
                                  {%- else -%}
                                      {{course[0][count|length-1]}}
                                  {%- endif -%}
                              {%- endif -%}
                          {%- endfor -%}  
                          &lt;/p&gt;
                          &lt;!-- &lt;p class=&quot;left&quot;&gt;{{course[0]}}&lt;/p&gt;
                          &lt;p class=&quot;right&quot;&gt;{{course[1]}}&lt;/p&gt;
                          &lt;p class=&quot;teacher&quot;&gt;{{course[2]}}&lt;/p&gt; --&gt;
                         {%- endif -%}
                        {%- endfor -%}    
                      &lt;/td&gt;
                  {% endif %}
              {% endfor %}
  
          &lt;/tr&gt;
  &lt;!-- Friday --&gt;
          &lt;tr&gt;
              &lt;td class=&quot;center&quot;&gt;
                  &lt;b&gt;Friday&lt;/b&gt;
              &lt;/td&gt;
              {% for course in friday %}
                  {% if course[1] != 0 %}
                      &lt;td colspan={{course[1]}}&gt;
                          {% set count = [] %}
                          {%- for y in range(0, 5) -%}
                              {%- if count|length &lt; course[0]|length -%}
                                  &lt;p class=&quot;left&quot;&gt;
                              
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
                                      &lt;/p&gt;
                                      {% set __ = count.append(1) %}
                                      &lt;p class = &quot;right&quot;&gt;
                                      {%- for z in range(count|length, course[0]|length) -%}
                                          {%- if course[0][count|length] == '@' -%}
                                          {%- else -%}
                                              {% set __ = count.append(1) %}
                                              {%- if course[0][count|length-1] == '_' -%}
                                                  {{' '}}
                                              {%- else -%}
                                                  {{course[0][count|length-1]}}
                                              {%- endif -%}
                                          {%- endif -%}
                                      {%- endfor -%}
  
                                  &lt;/p&gt;
                              {% set __ = count.append(1) %}
                          &lt;p class = &quot;teacher&quot;&gt;
                          {%- for z in range(count|length, course[0]|length) -%}
                              {%- if course[0][count|length] == '@' -%}
                              {%- else -%}
                                  {% set __ = count.append(1) %}
                                  {%- if course[0][count|length-1] == '_' -%}
                                      {{' '}}
                                  {%- else -%}
                                      {{course[0][count|length-1]}}
                                  {%- endif -%}
                              {%- endif -%}
                          {%- endfor -%}  
                          &lt;/p&gt;
                          &lt;!-- &lt;p class=&quot;left&quot;&gt;{{course[0]}}&lt;/p&gt;
                          &lt;p class=&quot;right&quot;&gt;{{course[1]}}&lt;/p&gt;
                          &lt;p class=&quot;teacher&quot;&gt;{{course[2]}}&lt;/p&gt; --&gt;
                         {%- endif -%}
                        {%- endfor -%}    
                      &lt;/td&gt;
                  {% endif %}
              {% endfor %}
  
          &lt;/tr&gt;
       &lt;/tbody&gt;
      &lt;/table&gt;
  
      &lt;p class = &quot;new-page&quot;&gt;&lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  <p>And the python file that I am running has the following code,</p>
  <pre><code>from typing import List
  import pdfkit
  from pdfkit.api import configuration
  from jinja2 import FileSystemLoader, Environment
  wkhtml_path = pdfkit.configuration(wkhtmltopdf = &quot;C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe&quot;)  #by using configuration you can add path value.
  
  class section:
      def __init__(self, id, course, section, instructor, room):
          self.id = id
          self.course = course
          self.section = section
          self.instructor = instructor
          self.room = room
  
  def generate_data():
      data = {}
  
      # For CS-1A
      data[&quot;CS-1A&quot;] = [[&quot;&quot; for i in range(5)] for j in range(5)]
      data[&quot;CS-1A&quot;][0][0] += &quot;Advance_Programming@Mr.Ashas@Room_#2 &quot;
      data[&quot;CS-1A&quot;][0][0] += &quot;Applied_Physics@Bilal@Room_#1 &quot;
      data[&quot;CS-1A&quot;][0][1] += &quot;Programming_Fundamentals@Muhammad_Bilal@Room_#1 &quot;
      data[&quot;CS-1A&quot;][0][3] += &quot;Programming_Fundamentals_Lab@Mr._Abid@Lab_#01 &quot;
      data[&quot;CS-1A&quot;][0][4] += &quot;Programming_Fundamentals_Lab@Mr._Abid@Lab_#01 &quot;
  
      # You may change all these for testing purposes. 
      # data[&quot;CS-1A&quot;][0][0].append(section(2, &quot;Programming Fundamentals&quot;, &quot;CS-1A&quot;, &quot;Bilal&quot;, &quot;Room #1&quot;))
      # data[&quot;CS-1A&quot;][0][1].append(section(3, &quot;Applied Physics&quot;, &quot;CS-1A&quot;, &quot;Muhammad Bilal&quot;, &quot;Room #5&quot;))
      # obj = section(4, &quot;Programming Lab&quot;, &quot;CS-1A&quot;, &quot;Mr. Abid&quot;, &quot;Lab #01&quot;)
      # data[&quot;CS-1A&quot;][0][1].append(obj)
      # data[&quot;CS-1A&quot;][0][2].append(obj)
      # data[&quot;CS-1A&quot;][0][4].append(section(5, &quot;English Communication&quot;, &quot;CS-1A1&quot;, &quot;Ms. Ayeza&quot;, &quot;Cal Lab&quot;))
      # data[&quot;CS-1A&quot;][0][4].append(section(6, &quot;English Communication&quot;, &quot;CS-1A2&quot;, &quot;Ms. Ayesha&quot;, &quot;GP Lab&quot;))
      # data[&quot;CS-1A&quot;][1][1].append(section(7, &quot;Linear Algebra&quot;, &quot;CS-1A&quot;, &quot;Ms. Zain&quot;, &quot;Romm #2&quot;))
      # obj = section(8, &quot;English Lab&quot;, &quot;CS-1A&quot;, &quot;Ms. Abida&quot;, &quot;Lab #04&quot;)
      # data[&quot;CS-1A&quot;][1][3].append(obj)
      # data[&quot;CS-1A&quot;][1][4].append(obj)
      # data[&quot;CS-1A&quot;][2][0].append(section(9, &quot;Social Studies&quot;, &quot;CS-1A&quot;, &quot;Mr. Zain Iqbal&quot;, &quot;Room #14&quot;))
      # data[&quot;CS-1A&quot;][2][4].append(section(10, &quot;Programming Fundamentals&quot;, &quot;CS-1A&quot;, &quot;Bilal&quot;, &quot;Room #15&quot;))
      # # No lectures on Thursday i.e. 3rd index
      # obj = section(11, &quot;English Lab&quot;, &quot;CS-1A&quot;, &quot;Ms. Abida&quot;, &quot;Lab #03&quot;)
      # data[&quot;CS-1A&quot;][4][1].append(obj)
      # data[&quot;CS-1A&quot;][4][2].append(obj)
      # data[&quot;CS-1A&quot;][4][2].append(section(12, &quot;English Communication&quot;, &quot;CS-1A1&quot;, &quot;Ms. Ayeza&quot;, &quot;Room #3&quot;))
      # data[&quot;CS-1A&quot;][4][2].append(section(13, &quot;English Communication&quot;, &quot;CS-1A2&quot;, &quot;Ms. Ayesha&quot;, &quot;GP Lab&quot;))
      #
      #
      #
      # # For CS-1B
      # data[&quot;CS-1B&quot;] = [[[] for i in range(5)] for j in range(5)]
      #
      # data[&quot;CS-1B&quot;][0][1].append(section(14, &quot;Advance Programming&quot;, &quot;CS-1B&quot;, &quot;Mr. Ali Hassan&quot;, &quot;Room #2&quot;))
      # data[&quot;CS-1B&quot;][0][2].append(section(15, &quot;English Comprehension and Communication&quot;, &quot;CS-1B&quot;, &quot;Mr. Bilal&quot;, &quot;Room #1&quot;))
      # obj = section(15, &quot;Software for Mobile and Devices&quot;, &quot;CS-1B&quot;, &quot;Mr. Jacob&quot;, &quot;Room #5&quot;)
      # data[&quot;CS-1B&quot;][1][1].append(obj)
      # data[&quot;CS-1B&quot;][1][2].append(obj)
      # data[&quot;CS-1B&quot;][1][3].append(section(17, &quot;Calculus and Geometrical Analytics&quot;, &quot;CS-1B&quot;, &quot;Ms. Nomi Khan&quot;, &quot;Room #06&quot;))
      # data[&quot;CS-1B&quot;][2][3].append(section(18, &quot;Introduction to Information and Communication Technology - Lab&quot;, &quot;CS-1B1&quot;, &quot;Ms. Sarah Niaz&quot;, &quot;Lab #01&quot;))
      # data[&quot;CS-1B&quot;][2][3].append(section(19, &quot;Introduction to Information and Communication Technology - Lab&quot;, &quot;CS-1B2&quot;, &quot;Ms. Julia John&quot;, &quot;Lab #06&quot;))
      # data[&quot;CS-1B&quot;][2][4].append(section(20, &quot;English Comprehenseion and Communication&quot;, &quot;Cs-1B&quot;, &quot;Mr. Lionel Boyle&quot;, &quot;Room #02&quot;))
      # data[&quot;CS-1B&quot;][3][3].append(section(21, &quot;Programming Fundamentals&quot;, &quot;CS-1B&quot;, &quot;Mr. Alex Niles&quot;, &quot;Room #3&quot;))
      # data[&quot;CS-1B&quot;][4][2].append(section(22, &quot;Linear Algebra&quot;, &quot;CS-1B&quot;, &quot;Ms. Ayesha&quot;, &quot;GP Lab&quot;))
  
      return data
  
  def organise_input_data(elements: List[List[str]]) -&gt; List[list]:
      &quot;&quot;&quot;
      Organises the input data to find double courses for easier use in templates
      &quot;&quot;&quot;
      new_elements = []
      for day in elements:
          last_course = None
          course_list = []
          index = 0
          for course in day:
              # cleanup data
              course = course.strip().replace(&quot; &quot;, &quot;&lt;hr&gt;&quot;)
              # check if long course (and not lunch time)
              if course != &quot;&quot; and course == last_course and index != 3:
                  course_list.remove((course, 1))
                  course_list.append((course, 2))
                  course_list.append((&quot;none&quot;, 0))
              else:
                  course_list.append((course.replace(&quot; &quot;, &quot;&lt;hr&gt;&quot;), 1))
              last_course = course
              index += 1
          new_elements.append(course_list)
  
      return new_elements
  
  
  def generate_html(template, name: str, elements: List[list]) -&gt; str:
  
      new_elements = organise_input_data(elements=elements)
  
      rendered = template.render(
          name=name,
          monday=new_elements[0],
          tuesday=new_elements[1],
          wednesday=new_elements[2],
          thursday=new_elements[3],
          friday=new_elements[4]
      )
  
      with open(f&quot;out_{name}.html&quot;, &quot;w+&quot;) as file:
          file.write(rendered)
  
      return rendered
  
  
  def run(input_data):
      # Init jinja
      file_loader = FileSystemLoader('.')
      env = Environment(loader=file_loader)
      template = env.get_template('template.html')
  
      full_text = &quot;&quot;
      for name, elements in input_data.items():
          full_text += generate_html(template=template, name=name, elements=elements)
  
      pdfkit.from_string(full_text, &quot;out.pdf&quot;, configuration = wkhtml_path)
  
  
  if __name__ == '__main__':
      data = generate_data()
      run(data)
  </code></pre>