我想從特定路徑打開並打印PDF文件,我以前的代碼完全打開並直接將打印命令發送到打印機。 現在我想要的是多個打印機在那裏,我必須選擇一個,然後我想發送打印命令,我不想要使用QPrintDialog,我的打印機名稱存儲在一個文本框中,並檢索該名稱並打印它通過該打印機,我在文本框設置:使用Qt打印PDF文件
我以前的代碼下面提及:
#include <QSettings>
#include <QProcess>
#include <QDebug>
int main(int argc, char *argv[])
{
const QString classesRoot = "HKEY_CLASSES_ROOT";
// get ID of .pdf extension
QSettings pdfSettings(classesRoot + "\\.pdf", QSettings::NativeFormat);
QString pdfId = pdfSettings.value("Default").toString();
// get path to default program that associated with 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 to pdf file.pdf"));
// print .pdf file
QProcess printProcess;
printProcess.start(printPath.arg("full path to pdf file.pdf"));
printProcess.waitForFinished(-1);
return 0;
}
您可以使用** Ghostscript **打印PDF文件:http://stackoverflow.com/questions/2599925/how-to-print-pdf-on-default-network-printer-using-ghostscript-gswin32c-exe-she – Yoonian