PDA

View Full Version : Create pdf, print silently to \\servername\printername



Pkora
4th June 2010, 10:26
So I want to create pdf, write some text, lines etc. and save i to some folder, and also I want to print this pdf silently (without any dialog) to printer
So this is what I've found

QTextDocument - has a print function
QPrinter- has a setPrinterName function - setPrinterName("\\servername\printername") ?
QPainter - has all the drawing functions

So something like this gathered from documentation



QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("test.pdf");
printer.setPrinterName("\\servername\printername"); // doable?

QPainter painter;
painter.begin(&printer);
painter.drawText(10, 10, "Test");
painter.end();


This should give me test.pdf which I want, and anything I want to draw, can with QPainter class...ok

and for printing I found some examples but it combines having
QTextEdit and QTextDocument,
then calling QTextEdit::setDocument(QTextDocument), and then
QTextDocument::print(&printer)

(I skipped actuall variables)

but well how to connect QTextDocument and mine pdf file
QTextDocument::print(&printer);
wont work, obviosly, must be I'm on wrong path

so how can I do that? to print it silently directly to printer,
before I switched to Qt I would use foxit command line utility like this
WinExec("C:\\foxit /p C:\\test.pdf",SW_SHOWNORMAL);

but now I see how great Qt is and how many options it has so why not to use them

I can't try anything since my qt is reconfiguring so any idea will be appreciated

thanks