2

I'm trying to print an html document from a QWebEngineView by using the print() method and a QPrinter instance that is required by this method.

The problem that I have is that in the resulting PDF I'm not able to select any text that is available. The PDF is somehow plain, just like a picture inside of the PDF file. Considering that Qt's WebEngine is the same as the one from Chromium (Google Chrome), they should behave in the same way but on the PDFs exported from Chrome I'm able to select the text. Is there a way to control how the pdf is exported?

P.S. I'm not using the printToPdf() method because it generates a very big pdf (aprox. 5MB).

cosmarc
  • 562
  • 3
  • 19

1 Answers1

0

At the cost of page/pdf quality, you can inject the QWebEngineView page to html and load the html into QTextDocument that can be printed ..

webview->page()->toHtml([this](const QString& result){handlePagePrint(result);});

void handlePagePrint(QString result)
{
    QTextDocument td;
    td.setHtml(result);
    td.print(&printer);
}
Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
  • this wont be the exact same page we want to see in print preview, because print style is different from pages style "which is specified in css". – MoreMag Jun 19 '19 at 04:38