question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python 3: Bad table formatting with empty columns

See original GitHub issue

Content of the columns are overlapped if there’s an empty cells.

Here is code for reproducing:

# -*- encoding: utf-8 -*-
from xhtml2pdf import pisa
import sys

py_version = '{0}.{1}'.format(sys.version_info[0], sys.version_info[1])
outputFilename = "bad_table_" + py_version + ".pdf"
source_html = '<html><body>' \
              '<table>' \
              '<tr>' \
              '<td>Item</td><td>Value 1</td><td>Value2</td><td>Value3</td>' \
              '</tr>' \
              '<tr>' \
              '<td>Item 1</td><td>11</td><td>12</td><td>13</td>' \
              '</tr>' \
              '<tr>' \
              '<td>Item 2</td><td>21</td><td>22</td><td>23</td>' \
              '</tr>' \
              '<tr>' \
              '<td>Item 3</td><td>31</td><td>32</td><td>33</td>' \
              '</tr>' \
              '<tr>' \
              '<td>TOTAL</td><td></td><td></td><td>100</td>' \
              '</tr>' \
              '</table>' \
              '</body></html>'

if __name__ == "__main__":
    result_file = open(outputFilename, "w+b")
    pisa_status = pisa.CreatePDF(
        source_html,
        dest=result_file)
    result_file.close()
    print(pisa_status)

And this is how results are compared. badtables

I’ve used a latest version from develop branch 1.a1

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
citizen-stigcommented, Apr 19, 2016

Yes, the problem appears only in Python3. I’ve described workaround and I’ll try to propose a fix for that

0reactions
LegoStormtrooprcommented, Mar 29, 2017

@arkadicolson The code for Python 2 and 3 is the same, can you state which version of XHTML2PDF you are on, and an example input and output?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I stop Tabula from automatically dropping empty ...
UPDATE: The best solution I could find was fiddling with the 'lattice' settings which determined how tables are read in Tabula (you can...
Read more >
Data Cleaning with Python and Pandas: Detecting Missing ...
Pandas will recognize both empty cells and “NA” types as missing values. ... case where there's missing values that have different formats.
Read more >
asciitable 0.8.0 documentation
An extensible ASCII table reader and writer for Python 2 and 3. Asciitable can read and write a wide range of ASCII table...
Read more >
Built-in Exceptions — Python 3.11.1 documentation
If str() is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty...
Read more >
Reading tables — Astropy v0.4.2
Guess table format¶ · At least two table columns · No column names are a float or int number · No column names...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found