Python 3 wkhtmltopdf Script to Convert HTML File to PDF or Website URL to PDF Document Using PDFKit Library Full Project For Beginners

Python 3 wkhtmltopdf Script to Convert HTML File to PDF or Website URL to PDF Document Using PDFKit Library Full Project For Beginners

 

Welcome folks today in this blog post we will be converting html files to pdf using pdfkit library. For this purpose we will be using python. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started we need to install the following library by using the pip command

 

pip install pdfkit

 

After installing this library you need to install wkhtmltopdf application from their official website specially if you are on windows

 

If you are linux you will use this command to install this software as shown below

 

sudo apt-get install wkhtmltopdf

 

Now after installing in windows you need to set the path variable like this. First of all we will find the full path of the wkhtmltopdf inside program files just copy this path and then add this to system path variable as shown in the below figure.

READ  Python PyQt5 Bulk Alexa Rank Checker From List of Websites in Text File and Save it as CSV File GUI Desktop App Full Project For Beginners

 

 

 

 

 

 

 

After setting the path variable just create an app.py file and copy paste the following code

 

app.py

 

So here we are converting the test.html to out.pdf so we are taking the local html file and then this python script converts the html file to pdf files using pdfkit library as shown below.

 

 

import pdfkit 
pdfkit.from_file('test.html', 'out.pdf')

 

 

After this we will be converting the website url to pdf document using pdfkit in the below example

 

 

import pdfkit 
pdfkit.from_url('https://www.google.co.in/','google.pdf')

 

 

 

 

 

Leave a Reply