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?
Asked
Active
Viewed 1,932 times
2
-
Is it forbidden to use any third party program ? You may invoke ghostscript which understands PDF and supports a lot of output languages. – Oncaphillis Oct 25 '14 at 11:46
-
yes,my boss forbidden me to use third-library,can i print ghostscript file via printer device directly?can i convert my pdf file to ghostscript file easyly? – heshmat askari Oct 25 '14 at 11:57
-
windows platform(windows xp,7) – heshmat askari Oct 25 '14 at 12:33
-
With ghostscript you would still have to figure out which printer type to serve. I think the most simpole approach would be to invoke acrobat reader see [here](http://stackoverflow.com/questions/619158/adobe-reader-command-line-reference) a specially the /t option. – Oncaphillis Oct 25 '14 at 12:37
-
in realy my pdf is encrypted and must not save in pdf file on disk, for this reason i can't using command line acrobat reader. – heshmat askari Oct 25 '14 at 13:19
-
how can i use ghostscript in QT? – heshmat askari Oct 25 '14 at 13:21
-
Well if you're not allowed to save on disk my guess is that ghostscript won't help you either. The part with the encryption is actually a quite substantial. Ghostscript would just be a PDF translator which generates printer specific output which you might simply copy to the printer of your choosing. – Oncaphillis Oct 25 '14 at 13:25
-
so,what can i do?any idea? – heshmat askari Oct 25 '14 at 13:29
-
don't know if it's possible to pipe a pdf stream into into acrobat reader from your aplication. – Oncaphillis Oct 25 '14 at 13:43
1 Answers
2
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());
}

Burak Hamuryen
- 128
- 6
-
i want to send pdf file to printer device(example network printer), i dont want to print my widget, – heshmat askari Oct 25 '14 at 14:10
-
OK, if you can render the file on the widget, than you can print like this. – Burak Hamuryen Oct 25 '14 at 14:14
-
i cant use mupdf and poppler for render pdf(realy i couldent compile this library for qt5),any render library or way exiss?? – heshmat askari Oct 26 '14 at 19:51