'I have a PyQt5 QWebEngineView does NOT print the same thing shows in the browser
So I have QWebEngineView app like below
import sys
from PyQt5 import QtWidgets, QtWebEngineWidgets
from PyQt5.QtCore import QUrl, QTimer
from PyQt5.QtGui import QPageLayout, QPageSize
from PyQt5.QtWidgets import QApplication
import argparse
def main():
parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--url", help="Type url")
args = parser.parse_args()
config = vars(args)
url = config['url']
app = QtWidgets.QApplication(sys.argv)
loader = QtWebEngineWidgets.QWebEngineView()
loader.setZoomFactor(1)
layout = QPageLayout()
layout.setPageSize(QPageSize(QPageSize.A4Extra))
layout.setOrientation(QPageLayout.Portrait)
loader.load(QUrl(url))
loader.page().pdfPrintingFinished.connect(lambda *args: QApplication.exit())
def emit_pdf(finished):
QTimer.singleShot(2000, lambda: loader.page().printToPdf("test.pdf", pageLayout=layout))
loader.loadFinished.connect(emit_pdf)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
I run the program like this python3 htmlToPdfnew.py --url https://www.w3schools.com/howto/howto_css_register_form.asp
so IF you load the url https://www.w3schools.com/howto/howto_css_register_form.asp from your browser you will see screen like below
IF you open the output test.pdf, you will see something like below
Compare above screens.
Why they are different ?
How can I get the full screen embedded to pdf like first picture ?
I had a look at online converter https://www.sejda.com/html-to-pdf
That online converter embeds full view to pdf.
So can I achieve the same with above python code ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


