
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert HTML to PDF Using Python
Python provides Pdfcrowd API v2 which is convert HTML documents to PDF. This API is very easy to use and the integration takes only a couple of lines of code.
Installation
Install the client library from PyPI $ pip install pdfcrowd
Conversion will be completed in following 3 Steps from Webpage/HTML to PDF
Step 1 − Download the library pdfkit
$ pip install pdfkit
Step 2 − Now download wkhtmltopdf
For Ubuntu/Debian −
sudo apt-get install wkhtmltopdf
For Windows −
(a) Download link : WKHTMLTOPDF (b) Set : PATH variable set binary folder in Environment variables.
Step 3 − Code in Python to Download −
(i) Already Saved HTML page
import pdfkit pdfkit.from_file('my_test.html', my_'output.pdf')
(ii) Convert by website URL
import pdfkit pdfkit.from_url('https://www.google.co.in/','my_testpdf.pdf')
(iii) Store text in PDF
import pdfkit pdfkit.from_string('my_testpdf ABC','testpdf.pdf')
Advertisements