title: Any idea why a python comclient PDF (from word document created by python docx ) does not tag table headers correctly?
body: <p>i have to create numerous (Americans with Disabilities Act) ADA accessibity compliant PDFs of long tables every year - a single table spans many pages.</p>
  <p>The data for the tables are on text files.
  I first use python Docx to create word documents of the tables that are properly spaced, formatted, and contain metadata such as title, author, etc.</p>
  <p>So far so good. If I do a preliminary check by opening that Word doc and using the Acrobat extension built into Word to create a PDF, the table header is accurately tagged when I run the Adobe Accessibility Checker.</p>
  <p>But i dont want to manually create each PDF, so I then use python Comclient to create  PDFs from the Word documents. Everything looks good except I get an error when I run the Accessibility checker saying the table headers failed.</p>
  <p>If I look at the PDF tags, the first row of the table  has a  tag with the word Path repeated over and over PathPathPathPathPathPathPathPathPathPathPathPathPath. After the Span tag, the table headers are correctly tagged as .
  <a href="https://i.stack.imgur.com/Fcvfk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fcvfk.jpg" alt="PDF tags bad" /></a></p>
  <p>That Span tag is not there on the PDFs created from the same document using the Acrobat extension built into Word, so I assume it is the reason for the Header failure when i create the PDF using the comclient python code.</p>
  <p><a href="https://i.stack.imgur.com/2KA2y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2KA2y.jpg" alt="PDF tags good" /></a></p>
  <p>Any ideas on what might be causing this Span tag and/or how to stop it?</p>
  <p>Possibly relevant docx code used to make headers:</p>
  <pre><code>from docx import Document
  from docx.shared import Cm, Pt, Inches
  from docx.oxml import OxmlElement
  from docx.oxml.shared import OxmlElement
  from docx.oxml.ns import qn
  import docx
  import os
  import sys
  import comtypes.client
  from docx.enum.text import WD_ALIGN_PARAGRAPH
  from docx.enum.table import WD_ALIGN_VERTICAL
     
  --function from github raphaelvalentin , much appreciated!
       def set_repeat_table_header(row):
              &quot;&quot;&quot; set repeat table row on every new page
              &quot;&quot;&quot;
              tr = row._tr
              trPr = tr.get_or_add_trPr()
              tblHeader = OxmlElement('w:tblHeader')
              tblHeader.set(qn('w:val'), &quot;true&quot;)
              trPr.append(tblHeader)
              return row
  
  --function from github AlbinoShadow, much appreciated: 
      def prevent_document_break(document):#keeps table rows from splitting in half over a page break
          &quot;&quot;&quot;https://github.com/python-openxml/python-docx/issues/245#event-621236139
             Globally prevent table cells from splitting across pages.
          &quot;&quot;&quot;
          tags = document.element.xpath('//w:tr')
          rows = len(tags)
          for row in range(0, rows):
              tag = tags[row]  # Specify which &lt;w:r&gt; tag you want
              child = OxmlElement('w:cantSplit')  # Create arbitrary tag
              tag.append(child)  # Append in the new tag
  
  doc = docx.Document()
  cp = doc.core_properties
  cp.author  = name #name defined previously
  cp.title = title #title defined previously
  table = doc.add_table(rows= row_ttl, cols= col_ttl)
  table.autofit = False 
  table.allow_autofit = False
  table.style='Light Grid Accent 1'
  set_repeat_table_header(table.rows[0])
  </code></pre>
  <p>Possibly relevant comclient code used to make pdfs</p>
  <pre><code>           pdf_name = file[:-3]+'pdf'
              prevent_document_break(doc)
              doc.save(ada_pdfs_folder+fldr+'/word_docs/' + file_name)
              wdFormatPDF = 17
              in_file = ada_pdfs_folder+fldr+'/word_docs/' + file_name
              out_file =ada_pdfs_folder+fldr+'/' + pdf_name
              word = comtypes.client.CreateObject('Word.Application')
              doc2 = word.Documents.Open(in_file)
              doc2.SaveAs(out_file, FileFormat=wdFormatPDF)
              doc2.Close()
              word.Quit()
  </code></pre>
  <p>Thanks for any thoughts or suggestions
  -Kimberly</p>