PDA

View Full Version : How can I export my user interface as pdf



ahmetturan
9th December 2013, 15:59
I want to export my qt window as pdf. How can I do that?. I found this link http://qt-project.org/wiki/Exporting_a_document_to_PDF. but this is for text I think. I want export everything what I saw on screen. How can I do that?

anda_skoa
9th December 2013, 18:16
Try calling your widget's render() method with a QPrinter configured for PDF output as the paint device.

Cheers,
_

Radek
9th December 2013, 19:45
No, it is not. QTextDocument is a "full sized" document supporting all kinds of formatting, including embedded images, tables and other bells and whistles. So you can create a document which includes pictures of your API along with an accompanying text and then print it in a file as a PDF theoretically. But I think this is a rather challenging decision: you need to write a "full sized" document editor for it.

IMO, there are far simpler methods. Create the images using some kind of a screen grabber then use a ready-to-use document editor that can output to a PDF (Libre Office, Open Office (starting from version 3 I think), even micro$oft office. Create a document and output to a PDF. Done.

ahmetturan
10th December 2013, 12:59
Thanks. I solved my problem



QPixmap pixmap;
pixmap=QPixmap::grabWindow(ui->widget->winId());

QPrinter printer;
printer.setOrientation(QPrinter::Landscape);
printer.setOutputFormat(QPrinter::PdfFormat);

printer.setOutputFileName(QApplication::applicatio nDirPath()+QDir::separator()+"file");

QPainter painter(&printer);
QRect rect=painter.viewport();
QSize size=pixmap.size();

size.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
painter.setWindow(pixmap.rect());

painter.drawPixmap(0,0,100,100,pixmap);