How to convert html to pdf using python


In many cases, it is required to convert HTML output into pdf. For eg:- Consider a scenario, in which you did some payment on a website, and they provide just an HTML receipt, but you require a pdf version of that HTML receipt.

So via this article we gonna show, how to convert HTML into pdf using python.


// installing library pdfkit

pip install pdfkit

// installing wkhtmltopdf 

sudo apt-get install wkhtmltopdf


// Case: 1

// if already saved html page =  test.html

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

//Case 2:
// if converting directly from a webpage

import pdfkit 
pdfkit.from_url('https://www.example.com/','out.pdf') 

//Case3 :
// passing multiple sources 
pdfkit.from_url(['google.com', 'xyz.com', 'facebook.com'], 'out.pdf') 
pdfkit.from_file(['file1.html', 'file2.html'], 'out.pdf') 



How to convert html to pdf using python
You may Also Like
Scroll to top