qpainter - HTML to PDF using Qt not show all characters - Stack Overflow

I am having an issue with exporting HTML to PDF using Qt version 6.8. Some characters simply do not app

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

相关推荐

  • qpainter - HTML to PDF using Qt not show all characters - Stack Overflow

    I am having an issue with exporting HTML to PDF using Qt version 6.8. Some characters simply do not app

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信