Convert html to pdf using Python/Flask
The page need render, You can use pdfkit:
https://pypi.python.org/pypi/pdfkit
https://github.com/JazzCore/python-pdfkit
Example in document.
import pdfkitpdfkit.from_url('http://google.com', 'out.pdf')pdfkit.from_file('test.html', 'out.pdf')pdfkit.from_string('Hello!', 'out.pdf') # Is your requirement?
Have you tried with Flask-WeasyPrint, which uses WeasyPrint? There are good examples in their web sites so I don't replicate them here.
Conversion in 3 Steps from Webpage/HTML to PDF
Step1: Download library pdfkit
$ pip install pdfkit
Step2: 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.
Step3: Code in Python to Download:
(i) Already Saved HTML page
import pdfkitpdfkit.from_file('test.html', 'out.pdf')
(ii) Convert by website URL
import pdfkitpdfkit.from_url('https://www.google.co.in/','shaurya.pdf')
(iii) Store text in PDF
import pdfkitpdfkit.from_string('Shaurya Stackoverflow','SOF.pdf')