gpt4 book ai didi

pdf - 如何从 Qt 应用程序创建 pdf 文件?

转载 作者:行者123 更新时间:2023-12-04 06:10:30 25 4
gpt4 key购买 nike

在我的 Qt 应用程序中,我正在进行一些网络测试。我必须根据测试输出创建报告。所以我需要以pdf格式创建报告。

有人可以让我知道如何将我的测试结果放在 pdf 文件中吗?我的结果包含使用 Qwt 库的图形。

最佳答案

此代码从 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();

关于pdf - 如何从 Qt 应用程序创建 pdf 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5134837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com