posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.44k stars 50 forks source link

Save to pdf producing junk output #226

Open ropeladder opened 4 months ago

ropeladder commented 4 months ago

Prework

Description

save() to pdf gives junk output. The page looks like this in Okular:

image

Reproducible example

import great_tables as gt
from great_tables.data import sp500

start_date = "2010-06-07"
end_date = "2010-06-14"

sp500_mini = sp500[(sp500["date"] >= start_date) & (sp500["date"] <= end_date)]

(
    gt.GT(data=sp500_mini)
    .tab_header(title="S&P 500", subtitle=f"{start_date} to {end_date}")
    .fmt_currency(columns=["open", "high", "low", "close"])
    .fmt_date(columns="date", date_style="wd_m_day_year")
    .fmt_number(columns="volume", compact=True)
    .cols_hide(columns="adj_close")
    .save("test.pdf")
)

test.pdf is the image posted above

Development environment

Additional context

(Yes, the Ubuntu and Chromium versions are old, it's at work and I can't do anything about it.)

Instead of Selenium could great_tables just use chromium-browser directly if it's installed? I'm able to output the table as html and then send that directly through chromium-browser --headless --print-to-pdf=output.pdf test.html. I suppose Selenium is more helpful if users have a different browser installed, though.

machow commented 1 month ago

Hey, do you mind trying this with the latest Great Tables release (v0.6.1), and seeing whether it works for you? We overhauled the .save() method, and it looked okay on my machine (but I realize there's a lot of browser variation out there 😬 )

ropeladder commented 1 week ago

Still not working for me, using 0.9.0. (the output is nominally less garbage, as I can make out "S&P 500" but not really anything else)

image

Same Chromium and Ubuntu versions as above. Selenium v4.22.0.