[SOLVED] Embedded Linux, Qt4 QPrinter: PDF file content is bold and ugly


I am creating a PDF file using QPrinter in Qt4.8,

QPrinter printer(QPrinter::HighResolution);
QTextDocument document;

// printer.setFullPage(true);
// printer.setMargins({ 20, 20, 20, 20});
// printer.setPageMargins(QMarginsF(10, 10, 10, 10));

But the result is very ugly text as in this image (rectangle in the below):
enter image description here

What is interesting is that following this answer, at some point I could get a very clear text as in the top rectangle in the image. But during refactoring something seems to be changed and I cannot get clear PDF files anymore. I tried every possible ways I know. No result. Could you help me?

BTW, in the Ubuntu laptop a PDF file is fine, but in the target device (Embedded Linux) the resulted PDF is not clear.

PS: I forgot to commit the working code, therefore this problem.


It seems the problem is not about QPrinter at all. When refactoring I changed html contents of QTextDocument and unsupported CSS was causing the problem. I changed this:

body {
    font-family: "Helvetica, Arial, sans-serif";  // quotes are not supported
    font-style: normal;
    font-size: 12px;
table.bordered , .bordered th, .bordered td {
    text-align: center;   // this is not supported also
    border-width: 1px;
    border-collapse: collapse;
    font-weight: normal;

To this:

table.bordered, .bordered th, .bordered td {
   border-width: 1px;
   border-collapse: collapse;
   font-weight: normal;
   font-family: Arial, sans-serif;
   font-size: 12px;

Now it is working.

Answered By – Bobur

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *