c++ - Print a PDF file using Qt -


i want open , print pdf file particular path, previous code work open , directly send print command printer. want multiple printer there , have select one, , after want send print command, don't want want use qprintdialog, printer name stored in textbox , retrieve name , print through printer set in textbox:

my previous code mention below:

#include <qsettings> #include <qprocess> #include <qdebug>  int main(int argc, char *argv[]) {     const qstring classesroot = "hkey_classes_root";      // id of .pdf extension     qsettings pdfsettings(classesroot + "\\.pdf", qsettings::nativeformat);     qstring pdfid = pdfsettings.value("default").tostring();      // path default program associated pdf files     qstring printpath = qsettings(classesroot + "\\" + pdfid + "\\shell\\print\\command", qsettings::nativeformat).value("default").tostring();     qstring openpath = qsettings(classesroot + "\\" + pdfid + "\\shell\\open\\command", qsettings::nativeformat).value("default").tostring();     qdebug() << "print path" << printpath;     qdebug() << "open path" << openpath;      // open .pdf file     qprocess::startdetached(openpath.arg("full path pdf file.pdf") );      // print .pdf file     qprocess printprocess;     printprocess.start(printpath.arg("full path pdf file.pdf") );     printprocess.waitforfinished(-1);      return 0; } 

or can change printer default printer during printing.

  1. change default printer printer
  2. print pdf
  3. restore old default printer

how retrieve , set default printer in windows: http://support.microsoft.com/default.aspx?scid=kb;en-us;246772

since qt has no functions system administration. qt,

  1. change default printer printer

    how default printer name?

    qprinterinfo::defaultprintername()

    from: http://doc.qt.io/qt-5/qprinterinfo.html#defaultprintername

    how set default printer?

    by excuting, rundll32 printui.dll,printuientry /y /n "your printer name"

    from: http://windowsitpro.com/windows/jsi-tip-8415-how-can-i-set-users-default-printer-batch-script

  2. print pdf know

  3. restore old default printer

    by executing, rundll32 printui.dll,printuientry /y /n "old default printer name"


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -