Tutorial Example

A Simple Guide to Convert HTML to PDF in Python – Python Tutorial

In python, converting a html file to pdf is very simple. We can use pdfkit library to do it. In this tutorial, we will write an example to show you how to convert.

Install pdfkit library

pip install pdfkit

Install wkhtmlpdf application

You can download it in here.

https://wkhtmltopdf.org/downloads.html

As win 10 system, you can choose 64 bit to download.

Then we can start to convert a html to pdf

Convert a html to pdf

import pdfkit
pdfkit.from_url('https://www.tutorialexamples.com', 'out-test.pdf')

However,  if you find OSError: No wkhtmltopdf executable found. you can read this tutorial to fix this error.

Fix OSError: No wkhtmltopdf executable found in Win 10 for pdfkit Beginner – Python pdfkit Tutorial