PYQT5 QWebEngineView low quality when printing

225 Views Asked by At

I am trying to print page from url using QWebEngineView in PyQt5. In preview QWebEngineView.show() it shows with normal quality, but when I print the page the quality is the lowest

First I thought that the problem is the bad printing device. But when I print the content of QTextEdit() using QTextEdit().document().print_() the quality was perfect


import os
import sys
import argparse

from PyQt5.QtCore import QUrl
from PyQt5.QtPrintSupport import QPrinter
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
import win32print

class PrinterView(QWebEngineView):
    def __init__(self, url=None, filename=None, do_preview=False, parent=None):
        super(PrinterView, self).__init__(parent)
        win32print.SetDefaultPrinter("XP-80C") 
        self.do_preview = do_preview
       
        self.load(QUrl('https://stackoverflow.com/questions/41710994/create-a-pdf-with-fillable-fields-python'))
        self.setZoomFactor(1)
      
      
        self.printer = QPrinter(QPrinter.HighResolution)
        self.printer.setOrientation(QPrinter.Portrait)
        self.printer.setFullPage(True)

        self.loadFinished.connect(self.onloadFinished)

    def print_completed(self, dsd):
        pass

    def onloadFinished(self):
        if self.do_preview:
            self.show()
        else:
            self.page().print(self.printer, self.print_completed)

Here is the printed version of stackoverflow page

Printed version

0

There are 0 best solutions below