How to create pdf file from Qt application?
Asked Answered
L

1

8

In my Qt application I am conducting some network tests. I have to create a report according to the test output. So I need to create the report in pdf format.

Can anybody please let me know how I can put my test results in a pdf file? My result contains graphs using the Qwt library.

Lach answered 27/2, 2011 at 17:55 Comment(0)
G
13

this code outputs pdf from html:

QTextDocument doc;
doc.setHtml("<h1>hello, I'm an head</h1>");
QPrinter printer;
printer.setOutputFileName("c:\\temp\\file.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);
doc.print(&printer);
printer.newPage();

I guess you can generate an html wrapper for your img and quickly print your image. Otherwise you might copy the image directly on the printer, since it is a paint device in a similar fashion

QPrinter printer;
QPainter painter(&printer);

printer.setOutputFileName("c:\\temp\\file.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);

painter.drawImage(QRect(0,0,100,100), <QImage loaded from your file>);
printer.newPage();
Gimbals answered 30/11, 2011 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.