2011-02-27 32 views
8

在我的Qt應用程序我進行一些網絡測試。我必須根據測試輸出創建一個報告。所以我需要以pdf格式創建報告。如何創建Qt應用程序PDF文件?

可有人請讓我知道我可以把我的測試結果PDF文件?我的結果包含使用Qwt庫的圖表。

回答

13

此代碼的HTML輸出PDF:

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(); 

我想你可以爲您的IMG的HTML包裝和快速打印圖像。否則,你可能會在圖像直接在打印機上覆制,因爲它是在一個類似的方式油漆設備

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(); 
相關問題