tags:

views:

469

answers:

6

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.

So i am stuck as i don't know how to work around this problem.

Also i am a novice in QT , can anyone provide good reference about QT application's lifecycle, event loops and related stuff.

thanks in advance.

Ashish

+2  A: 

Well, actually, I just use Firefox to do "Print to File" and select PDF as the filetype. But that's for manual work - although I suppose you could script Firefox.

I think in a Linux environment - and I'm assuming Linux/Unix because you mentioned Qt - that you could probably string together a couple of nx command-line apps. Possibly enscript has something that would help. If not, I'm pretty sure I've seen other solutions, just can't recall them off the top of my head. If you can transform the HTML to Postscript, getting a PDF out of it is trivial.

Tim H
+1  A: 

If HTML4 and (parts of) CSS1 suffice for your needs, then you can use QTextDocument together with QPrinter in a separate thread.

+1  A: 

"Programming with Qt, Second Edition", O'Reilly, is excellent but only covers Qt3. A lot of the basic still apply to Qt 4.5.

"C++ GUI Programming with Qt 4 (2nd Edition)", ISBN 0132354160, is not bad.

The Qt docs contain examples and tutorials too.

Eric M
+1  A: 

It's not clear to me why you can't initialize a jar with GUI classes from within child threads. Is this an artificial limitation set on Jambi by the trolls?

I took note of this example on Rendering a webpage with Qt and Webkit to a QPixmap, which theoretically doesn't need to show anything on the screen. QWebPage and QWebFrame both inherit QObject. Using the sample code from the above link, it should be possible to get a webpage's rendered contents without a GUI.

erjiang
the "trolls" :D I like the slur
Here Be Wolves
A: 

Hi Ashish,

Were you able to complete your task? Can you share some details?

Thanks, Agarwal G

A: 

My primary task was to get html to pdf conversion for printing the pdf.

I tried to get QT jambi (QT webkit C++ api also) to work in multithreaded environment but could not.

My final solution was as follows:

I used ‘wkhtmltopdf’ native binary from here,

wrote a java wrapper capturing the standard input and output streams.

Initialized the ‘wkhtmltopdf’ binary for each java thread that required the html to pdf conversion.

Also i never worked on erjiang's advice because by then I had moved out of the task and never got time to work on his advice.

Ashish