How to create a pdf file from a Qt application?

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

Can someone please let me know how I can put the results of my test into a PDF file? My result contains graphs using the Qwt library.

+8
graph pdf qt4 qwt qprinter
source share
1 answer

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 think you can create a html wrapper for your img and quickly print your image. Otherwise, you can copy the image directly to the printer, as this is a drawing device in a similar way.

 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(); 
+13
source share

All Articles