QWebView problem with pdf
Hi,
The following code results in an empty pdf file whereas when I show() the component, the html code displays correctly.
Any idea?
Here is the source:
Code:
#include <QtCore>
#include <QtGui>
#include <QtWebKit>
int main(int argc, char *argv[]) {
qPrinter
->setOutputFormat
(QPrinter::PdfFormat);
qPrinter->setOutputFileName("out.pdf");
return 1;
while (!file.atEnd()) {
text += file.readLine();
}
QWebView *qWebView = new QWebView();
qWebView->setMinimumSize(1024,768);
qWebView->show();
qWebView->setHtml(text);
qWebView->show();
qWebView->print(qPrinter);
return app.exec();
}
The file in.txt contains only:
Code:
<html>
<body
helloWorld
</body>
</html>
Thanks for your help.
Best regards,
Oscar
Re: QWebView problem with pdf
Try setting the viewport size of the associated web page.
Re: QWebView problem with pdf
Thank you wysota for your reply.
I tried:
qWebView->page()->setViewportSize(QSize(2000,2000));
before
qWebView->print(qPrinter);
But the result is the same...Grrrr
Maybe I've got something wrong in my config.
Do you get a valid pdf with this example? (I'm testing it under Vista)
Best regards,
Oscar
Re: QWebView problem with pdf
I didn't try. But you don't need a web view widget. All you need is QWebPage with its mainFrame where you can set the content using setHtml().
Re: QWebView problem with pdf
The problem is the same with the use of a QWebPage class...
Here is the code:
Code:
#include <QtCore>
#include <QtGui>
#include <QtWebKit>
int main(int argc, char *argv[]) {
qPrinter
->setOutputFormat
(QPrinter::PdfFormat);
qPrinter->setOutputFileName("out.pdf");
QString text
= "<html> <body> coucou <br>coucou br>coucou <br>coucou <br>coucou <br>coucou <br>coucou </body> </html>";
QWebPage *qWebPage = new QWebPage();
qWebPage->mainFrame()->setHtml(text);
qWebPage
->setViewportSize
(QSize(2000,
2000));
qWebPage->mainFrame()->print(qPrinter);
return app.exec();
}
Any idea of what I'm missing?
Best regards,
Oscar
Re: QWebView problem with pdf
Well, I've found a html->pdf converter that's working.
I was missing the following line:
Code:
connect(qWebView, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
Now, everything is ok.
Best regards,
Oscar