How to write a table from CSV to PDF using Python
12,175
i really like using pdfkit
for these things.
setup is dead simple, just do pip install pdfkit
and install wkhtmltopdf
on your system.
and then from a python-commandline of your liking, do:
import pdfkit
pdfkit.from_file('/path/to/your/testcsv.csv',
'/path/of/output/testcsv.pdf')
For windows (or if your wkhtmltopdf is not in $PATH), you can provide an optional configuration-parameter:
config = pdfkit.configuration(wkhtmltopdf='/path/to/wkhtmltopdf')
pdfkit.from_file('/path/to/your/testcsv.csv',
'/path/of/output/testcsv.pdf',
configuration=config
)
more on this here in 'Configuration'-Section.
Related videos on Youtube
Author by
Riccardo
Updated on June 04, 2022Comments
-
Riccardo almost 2 years
I have a
CSV
file which contains the following table:users passwords company Admin test_psw test_cmp test_user1 test_psw1 test_cmp1 ... ... ... ... ... ...
where
users
,passwords
andcompany
are the header of the table and the table itself can dynamically grow up.How can I write this kind of table to a
PDF
file usingpython
? I had a look onreportlab
library, but came out with no ideas.-
joppich about 6 yearsdo you need to do any data processing between reading the csv and writing to pdf?
-
Riccardo about 6 years@joppich No, bu the PDF must be readable and upgradable.
-
-
Riccardo about 6 yearsit gives me the following error
OSError: No wkhtmltopdf executable found: "b''" If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf
Evend after installingwkhtmltopdf
-
joppich about 6 yearssorry, updated my answer to point out that dependency. what os are you on?
-
Riccardo about 6 yearsI'm on Windows 10
-
joppich about 6 yearsprovided some additional info, hope it helps. i don't have windows, thus untested
-
Riccardo about 6 yearsthanks man, but it gives me the following error:
Loading pages (1/6) Error: Failed loading page file:///C:/Users/r.spampinato/PycharmProjects/test/reports/1.1-IAM.csv (sometimes it will work just to ignore this error with --load-error-handling ignore) Exit with code 1, due to unknown error.
-
joppich about 6 yearsthat
--load-error-handling ignore
-thing is remarkably unhelpful, wow... sorry, i'm at a loss here. good luck, though. -
Miffy about 5 yearsOSError: No wkhtmltopdf executable found: "b''" If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf Evend after installing wkhtmltopdf. Im also getting same error. And Im using Mac OS. Please help