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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744751082a4591600.html
评论列表(0条)