Important: Please read the Qt Code of Conduct -

Print pdf file to local printer in Windows

  • I'm trying to send a PDF file from my local hard disk to my local printer (HP Deskjet) under Windows 10 in C++ but I'm having problems because the printing dialog is not displayed and nothing is printed.

        QTextDocument document;
        QPrinter printer(QPrinter::PrinterResolution);
        printer.setPageMargins(QMarginsF(15, 15, 15, 15));
        QPrinter printer1(QPrinter::HighResolution);
                QPrintDialog *dlg = new QPrintDialog(&printer1,this);
                dlg->setWindowTitle(QObject::tr("Print Document"));
                if(dlg->exec() == QDialog::Accepted) {
                delete dlg;

    The first piece of code works properly because the HTML document is created and saved to my local hard drive.
    The second piece of code doesn't work and the printing dialog is not displayed.

    I also get this error:

    QPrintDialog: Cannot be used on non-native printers

    How can I solve it? I tried to search in this forum about the same problem and I tried different solutions but nothing worked.

  • Lifetime Qt Champion


    Based on your code, you are in fact generating a PDF from some html input. Hence you have a file output.

    The fact that there's no dialog is related to that as well.

  • Thank you for your answer and your support.

    I would like to both generate a PDF and load a PDF file from the disk and to send it to my printer.

    How can I do it?

  • @Marcus-Barnet
    I think you should at least delete these two lines


    That won't load your pdf file.
    Without them you can have your dialog displayed.

Log in to reply