I have made som drawings in a mainwindow and now I would like to export it to a pdf file or postscript. How can I do that?
I have made som drawings in a mainwindow and now I would like to export it to a pdf file or postscript. How can I do that?
Try painting on a QPrinter (whose output format is set to QPrinter::PdfFormat).
EDIT: an example:
Qt Code:
printer.setOutputFileName("test.pdf"); QPainter painter; painter.begin(&printer); // draw the content // painter.draw..(..); painter.end();To copy to clipboard, switch view to plain text mode
Last edited by jpn; 7th April 2006 at 09:31.
J-P Nurmi
..and if I want print into a pdf the content of myGLWidget(it draw with paintGL())?
Regards
Save it into QImage or QPixmap using appropriate methods from QGLWidget and then print as usual.
thanks, to print directly my scene do I need insert an istruction like :
because my printer starts but print nothing...Qt Code:
qi.save(base_file + ".png","PNG"); painter.begin(&printer); /////painter.draw(qi);??????????????? Is it there? painter.end();To copy to clipboard, switch view to plain text mode
Regards
PDF is a scalable format, what gets lost doing it via a pixmap/image.Originally Posted by wysota
If vector data has to be painted, one should always try to render the PDF documents with QPainter using drawing primitives like lines, rects ... . Of course the geometry of these primitives has to be in qreals.
HTH,
Uwe
sorry but my question isn't relative to pdf format; I save the content of myGLWidget in a QImage qi; now I'd like to print it! the printer starts but the sheet is white. What am I missing? Thanks
Regards
Do you paint anything? See QPainter::drawImage().
For example:
Qt Code:
painter.drawImage(0,0,qi);To copy to clipboard, switch view to plain text mode
J-P Nurmi
I tried this but print nothing again....
Qt Code:
qi.save(base_file + ".png","PNG"); printer.setFullPage( TRUE ); if ( printer.setup(this) ) { // printer dialog statusBar()->message( "Printing..." ); QPainter p; QPainter painter; painter.drawImage(0,0,qi, 10,10, 20,20); if( !painter.begin( &printer ) ) { // paint on printer statusBar()->message( "Printing aborted", 2000 ); return; } painter.end(); statusBar()->message(""); }To copy to clipboard, switch view to plain text mode
Regards
The point is this is an OpenGL widget and I doubt you'll be able to use QPainter directly with it (meaning without GL context). IMHO you have to convert it to a bitmap first.Originally Posted by Uwe
Qt Code:
if (printer.setup(this)) { painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); painter.setWindow(qi.rect()); painter.drawImage(0, 0, qi); }To copy to clipboard, switch view to plain text mode
Last edited by mickey; 8th April 2006 at 10:25.
Regards
Bookmarks