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.