Exporting a document to PDF

From Qt Wiki
Revision as of 08:04, 28 May 2015 by Olivier M. (talk | contribs)
Jump to navigation Jump to search

Found it very easy to convert a QTextDocument to PDF in Qt, and useful in scenarios like creating reports etc.

For example, consider the following snippet:

QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "untitled", tr("PDF Document (....pdf)"));
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
QTextDocument doc;
doc->print(&printer);