admin管理员组文章数量:1391999
I am having an issue with exporting HTML to PDF using Qt version 6.8. Some characters simply do not appear in the final file, and interestingly, if I try to select the text and press Ctrl+C and then Ctrl+V, the text is pasted, meaning the content is there but not visible. Does anyone have any idea why this happens? The same code compiled with version 6.6 exports the file perfectly.
#include <QApplication>
#include <QPrinter>
#include <QPainter>
#include <QTextDocument>
#include <QFileDialog>
#include <QMessageBox>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QString htmlContent = R"(
<html>
<head>
<style>
body { font-family: 'Arial'; font-size: 14px; }
h1 { color: blue; }
</style>
</head>
<body>
<h1>Xuxu</h1>
<p>Export html to pdf using qt6_8</p>
</body>
</html>
)";
QPrinter printer(QPrinter::PrinterResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("xuxu.pdf");
printer.setPageSize(QPageSize::A4);
printer.setPageMargins(QMarginsF(12, 16, 12, 20));
QTextDocument doc;
doc.setHtml(htmlContent);
QPainter painter(&printer);
doc.drawContents(&painter);
painter.end();
QMessageBox::information(nullptr, "Success", "Xuxu created!");
return app.exec();
}
Here are two images that demonstrate my problem.
本文标签: qpainterHTML to PDF using Qt not show all charactersStack Overflow
版权声明:本文标题:qpainter - HTML to PDF using Qt not show all characters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744751082a2623182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论