Exporting a document to PDF
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);