[Qt-interest] Printing to pdf on windows

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


Hi again,

The usual story: you figure it out just after having asked. The addition of 
printer.setOutputFormat(QPrinter::PdfFormat);
did the trick.

Thanks anyway.

Btw; why did the code _just work_ on Linux without the above statement?

--
Christopher

On Sun, 1 Mar 2009 14:36:23 +0100, Christopher Rasch-Olsen Raa <christopher at technophile.info> wrote:
> 
> 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
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
--
Christopher




More information about the Qt-interest-old mailing list