[Qt-interest] Printing to pdf on windows

Christopher Rasch-Olsen Raa christopher at technophile.info
Sun Mar 1 14:36:23 CET 2009


Hi all,

In an application I've written there is a choice for the user to print certain things to pdf. This works like a charm on linux, but when I tested it on Windows XP empty files showed up and I got the following output in console:

---
QWin32PrintEngine::begin: StartPage failed (The handle is invalid.)
QPainter::begin(): Returned false
QPainter::setFont: Painter not active
QPainter::setFont: Painter not active
QPainter::setFont: Painter not active
QPainter::setFont: Painter not active
QPainter::end: Painter not active, aborted
---

Do any of you know whats wrong here? I've tried looking at the configure-flags for Qt (4.4.0 that I'm using) and none of them say anything about having to compile in pdf-libs as far as I can tell.

I've also tried installing a separate pdf-printer (CutePDF) so the system at least have an availailable printer capable of printing to pdf. I don't see why this should be required though, since I assumed Qt did all the pdf-magic itself.


The code that sets up printing is this;

---
QPainter painter;
QPrinter printer;
QTemporaryFile tempFile;
if(tempFile.open()) {
  printer.setOutputFileName(tempFile.fileName());
  printer.setPaperSize(QPrinter::A4);
  painter.begin(&printer);
  // Do printing magic
  painter.end();
}
---

Am I way off track here?

--
Christopher




More information about the Qt-interest-old mailing list