Python – Converting XLSX to PDF

As my original answer was deleted and is eventually a bit useful, I repost it here.

You could do it in 3 steps:

  1. excel to pandas: pandas.read_excel
  2. pandas to HTML: pandas.DataFrame.to_html
  3. HTML to pdf: python-pdfkit (git), python-pdfkit (pypi.org)
import pandas as pd
import pdfkit

df = pd.read_excel("file.xlsx")
df.to_html("file.html")
pdfkit.from_file("file.html", "file.pdf")

install:

sudo pip3.6 install pandas xlrd pdfkit
sudo apt-get install wkhtmltopdf 

Leave a Comment