I have tried to write some code to print a pdf file using Qt but somehow it's not working. If anybody has any idea to solve this problem, please provide your tips.
void ChartViewer::onprintBtnClicked(){
String filename = QFileDialog::getOpenFileName(this,"Open File",QString(),"Pdf File(*.pdf)");
qDebug()<<"Print file name is "<<filename;
if(!filename.isEmpty()) {
if(QFileInfo(filename).suffix().isEmpty())
filename.append(".pdf");
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(filename);
QPrintDialog*dlg = new QPrintDialog(&printer,this);
if(textedit->textCursor().hasSelection())
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Print Document"));
if(dlg->exec() == QDialog::Accepted) {
textedit->print(&printer);
}
delete dlg;
}
}