简体   繁体   中英

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;
document.setHtml(html);

printer.setOrientation(QPrinter::Landscape);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(fName);
// printer.setFullPage(true);
// printer.setMargins({ 20, 20, 20, 20});
// printer.setPageMargins(QMarginsF(10, 10, 10, 10));
document.documentLayout()->setPaintDevice(&printer);
document.setPageSize(printer.pageRect().size());
document.print(&printer);

But the result is very ugly text as in this image (rectangle in the below): 在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM