15

I want to create a print button for an HTML file. Well, window.print(). But this does not work because the web browser embedded in the software was developed by my company itself. It does not support print.

This web browser was using WebKit, and I only knew a little about Qt and WebKit.

So, how web browser deals with window.print?

Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
slayerxj
  • 273
  • 1
  • 8
  • 7
    The sequence of the 'window.print' for QT port is: window.print-> DOMWindow::print -> Chrome::print -> ChromeClient::print (ChromClientQt.cpp) -> emit m_webPage->printRequested By default, the the QWebPage::printRequested is not connected to any slot. You should add a slot like 'LauncherWindow::print' do (Show a preview dialog and print using QWebFrame::print). If your customized web browser doesn't use QT port, you need to implement the 'print' feature for your port. Hope it could help you. – Shen Weizheng Mar 27 '13 at 13:45
  • 2
    Shen: I think your comment deserves to be promoted to a full answer. As it is the right answer. – peppe Jun 06 '13 at 07:04

2 Answers2

0

Consider sending the content of the HTML/CSS (or a link) via AJAX to a server side print server, which then renders the HTML and sends it to the network printer. Another option is to create a browser plugin with NSAPI (C++). Another option is to embed a Java applet, which takes the HTML, renders it, and sends it to the printer.

Chloe
  • 25,162
  • 40
  • 190
  • 357
0

Alter the HTML file so that if a query string argument like ?print=1 is present it will automatically call window.print(). Then just open your-file.html?print=1 in a separate browser process.

Dave
  • 900
  • 6
  • 22
  • In objective-c webkit, you need to set a delegate to make window.print() works. Qt, supposedly, need something like this to make window.print() works too. What is needed is the anwser to this question. – Ratata Tata Jun 10 '13 at 16:25
  • Ah, you're right. I must have misread. Going to upvote the guy who had the answer then. – Dave Jun 18 '13 at 14:01