Eskil, Thanks a lot for your valuable response.
Though your response was totally correct as per my question but my requirements have changed a little bit. Let me clear out my requirements: 1. To provide java class that can be used to generate PDF stream from input HTML/(Markup) stream (rendered by webkit rendering engine) without involving any GUI component. 2. The java class should be thread safe and should be able to support multithreading. 3. Since the java class is to be used for a cloud service (server based)environment so utmost care have to be provided for memory management and usage of minimal amount of resources at runtime, so that large number of requests can be processed at server side simultaneously. Based on your valuable response, I am thinking of a solution that would be of the following kind as elaborated: 1. I would be creating a pool of QWebPage objects via main thread during QApplication initialization. 2. A request queue would be maintained , so that as soon as a request for HTML to PDF conversion comes in , I would redirect the request to one of the QWebPage object on a separate thread as suggested by you using QObject.moveToThread() 3. Thread states would be maintained so that QWebPage objects can be reused to process further request of HTML to PDf conversion. Now some of the bottlenecks for above solution that I can see are as follows: 1. My main objective is to redirect the rendered HTML(Markup) (generated by underlying WebKit rendering engine) to an output PDF Stream, for this I am creating QWebPage like GUI objects that are possibly a huge burden on memory and are also restricting multithreading. 2. Is there a direct non GUI QT class or component that is probably used by QWebPage that I can use for above mentioned purpose? 3. Solution may not be restricted to java language(Jambi), QT C++ solution too are welcome as I am open to writing my own JNI interface. Thanks in advance. With regards Ashish Sharma -----Original Message----- From: Eskil Abrahamsen Blomfeldt [mailto:[email protected]] Sent: Wednesday, July 08, 2009 4:05 PM To: Sharma, Ashish Cc: [email protected] Subject: Re: [Qt-jambi-interest] Html to pdf conversion Sharma, Ashish wrote: > > Hello, > > I am using Qt webkit Jambi API's to convert HTML to PDF. > > My target is to create a jar for above conversion so that it could be > used in a multithreading environment, but since QWebPage and QWebframe > (QT webkit) are GUI classes, therefore the jar classes cannot be > initialized from child threads. > It's true that certain actions are restricted to the gui thread (such as using widgets), but painting to a printer is allowed, as described here: http://doc.trolltech.com/qtjambi-4.5.0_01/com/trolltech/qt/qtjambi-threads.html#painting-in-threads A restriction on QWebPage is that it has to be constructed in the GUI thread, since it accesses QApplication. However, you can use QObject.moveToThread() to move QObjects over to a different thread than the one that created it. See the attached example of how to make a thread-based web page renderer that renders into a .pdf. (it's a quick&dirty example, so please excuse any bugs, but it should at least illustrate how to achieve what you need.) The example makes a widget which monitors the progress of loading the web page. The QWebPage is constructed in the gui thread, and made a child of the runnable object. Then the entire hierarchy is moved to the thread in question. The run() method in the runnable starts loading the web page, and when it completes, the web page is rendered into a .pdf-printer and the application is shut down. > Also i am a novice in QT , can anyone provide good reference about QT > application's lifecycle, event loops and related stuff. > Threads and event loops are described here: http://doc.trolltech.com/qtjambi-4.5.0_01/com/trolltech/qt/qtjambi-threads.html And here are a few whitepapers which may contain more information: https://www.qtsoftware.com/files/pdf -- Eskil
WebFrameInThread.java
Description: WebFrameInThread.java
_______________________________________________ Qt-jambi-interest mailing list [email protected] http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
