PDA

View Full Version : How to save file as ".pdf" from QPrinter



nifei
2nd March 2009, 10:22
Hi, all,
I want to save file as "outpuf.pdf" that is previewed via QPrintPreviewWidget. according to Qt's assistant, void QPrinter::setOutputToFile ( bool enable ) can be used, however, when i called this function, error C2039: 'setOutputToFile' : is not a member of 'QPrinter' occurs.

Why?

lyuts
2nd March 2009, 11:42
You should use


yourPrinter.setOutputFormat (QPrinter::PdfFormat);

pastor
2nd March 2009, 11:52
'setOutputToFile' is a member of of the Qt 3 support layer. You should use following:

printer.setOutputFormat(QPrinter::PdfFormat);

nifei
5th March 2009, 07:33
I supposed that "out.pdf" will be created automatically when the slot print(QPrinter*) is invoked by QPrintPreviewWidget::paintRequested(QPrinter*), but i was wrong. I just called print(QPrinter*) and the file is created.