Not really. I have no use for QPainter. But nevertheless, I have fixed the problem. For anyone having the same problem, here is a solution. Define a script in your HEAD tags in the HTML content with getters for page height and width:

Qt Code:
  1. <script LANGUAGE="JavaScript">
  2. function getHeight ()
  3. {
  4. return window.document.body.scrollHeight;
  5. }
  6. function getWidth ()
  7. {
  8. return window.document.body.scrollWidth;
  9. }
  10. </script>
To copy to clipboard, switch view to plain text mode 

Now in the code where you get the page content from the webview after loadFinished signal has been emitted, try this:

Qt Code:
  1. QWebView* view = dynamic_cast<QWebView *>(sender());
  2. QVariant heightVariant = view->page()->mainFrame()->evaluateJavaScript("getHeight()");
  3. QVariant widthVariant = view->page()->mainFrame()->evaluateJavaScript("getWidth()");
  4. QPrinter *printer = new QPrinter();
  5. printer->setOutputFileName("<path to pdf>");
  6. printer->setOutputFormat(QPrinter::PdfFormat);
  7. printer->setOrientation(QPrinter::Portrait);
  8. printer->setPaperSize(QSize(widthVariant.toInt(),heightVariant.toInt()),QPrinter::Point);
  9. view->page()->mainFrame()->print(printer);
To copy to clipboard, switch view to plain text mode 

That solves the problem.