heshmat askari
heshmat askari

Reputation: 21

print pdf file via printer device in qt

i am new C++ QT programmer,i want to print multi pdf files via my printer device(or network printer),i searched and find this tutorial: Qt Handling PDF file but i can't compile MuPDF and Poppler and use these third-party libs in my application.my pdf file encrypted too and must print file from memory. is way to print pdf file via my printer device?

Upvotes: 2

Views: 2015

Answers (1)

Burak Hamuryen
Burak Hamuryen

Reputation: 128

Hello you can use something like this.

QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Portrait);
QPrintDialog dlg(&printer, this);
dlg.setWindowTitle("Print");

if (dlg.exec() == QDialog::Accepted)
{
    QWidget* widget = new QWidget(his); // this widget is your pdf widget
    QPixmap printPixmap(widget->width(),widget->height());
    widget->render(&printPixmap,QPoint(),QRegion(0,0,widget->width(),widget->height()));
    QPainter painterPixmap(&printer);
    painterPixmap.scale(4,4);
    painterPixmap.drawPixmap(printer.pageRect().topLeft(), printPixmap, printPixmap.rect());
}

Upvotes: 2

Related Questions