Quantcast
Channel: Active questions tagged qpainter - Stack Overflow
Viewing all articles
Browse latest Browse all 58

HTML to PDF using Qt not show all characters

$
0
0

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.
image1

image2


Viewing all articles
Browse latest Browse all 58

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>