PDA

View Full Version : Is Qt right for this job?



silkodyssey
7th October 2008, 13:14
I want to write a program to convert html files to pdfs that supports the linux and windows platforms. I may not have time to implement an html parser so I was wondering would it be possible to use a Qt widget to load the html file and then have Qt print it to pdf. I was thinking of QWebkit but maybe there are other options thanks.

spirit
7th October 2008, 13:23
you can load html using QTextEdit (http://doc.trolltech.com/4.4/qtextedit.html), QTextBrowser (http://doc.trolltech.com/4.4/qtextbrowser.html), QWebView (http://doc.trolltech.com/4.4/qwebview.html).

montylee
7th October 2008, 14:57
i don't know if using Qt you can print anything to PDF. But you can try using PDF convertors like Ghostscript etc...which are also cross-platform.

So, use Qt's web widgets to display the HTML page and use Ghostscript etc... in the background to convert it to PDF.

netuno
7th October 2008, 15:59
It's easy to print to a PDF file with Qt. I've used it with several components but not with webkit. But from what I look at the docs, it has a print function so you're good to go.
Just create a printer object and set it's format to PDF. Here's a code sample:



QWebView *webkit = new QWebView();
QPrinter printer(QPrinter::HighResolution);

printer.setPageSize(QPrinter::A4);
printer.setOutputFileName("cartao.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);

webkit->load(QUrl("http://www.qtcentre.org/forum/"));
webkit->print(&printer);

That should get you going.

Qt for multi-platform is very good. And for this task you need, it gets the job done easy.

Good luck!

spud
8th October 2008, 18:51
Check out cutycapt (http://cutycapt.sourceforge.net/).