I have tried using wkhtml and weasyprint libraries but all of these render a blank pdf page. The only option that worked was pdfcrowd but this is a paid library. I found several options using PyQt for converting a web-page:
import sys
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
app = QtWidgets.QApplication(sys.argv)
loader = QtWebEngineWidgets.QWebEngineView()
loader.setZoomFactor(1)
loader.page().pdfPrintingFinished.connect(
lambda *args: print('finished:', args))
loader.load(QtCore.QUrl('https://en.wikipedia.org/wiki/Main_Page'))
def emit_pdf(finished):
loader.show()
loader.page().printToPdf("test.pdf")
loader.loadFinished.connect(emit_pdf)
app.exec()
However, I am not too sure how to adapt this to a locally saved html file.