Richardson Ansong
Richardson Ansong

Reputation: 790

QPrinter output to pdf is not equivalent to the paper/page size (A4)

I am trying to output a QWidget ui to a pdf file like this;

const QString filename = "class1bills.pdf";

printer = new QPrinter(QPrinter::HighResolution);
printer->setOutputFormat(QPrinter::PdfFormat);
printer->setOrientation(QPrinter::Portrait);
printer->setPaperSize(QPrinter::A4);
printer->setPageSize(QPrinter::A4);
printer->setPageMargins (15,15,15,15,QPrinter::Millimeter);
printer->setFullPage(false);
printer->setOutputFileName(filename);

painter = new QPainter(printer);

class1Bill->render(painter, QPoint(), QRegion(), QWidget::DrawChildren | QWidget::DrawWindowBackground);

painter->begin(printer);
painter->end();

assert(QFile::exists(filename)); 

class1Bill is an object of the class that inherits QWidget. Everything works fine but when i open the pdf file, i expect the widget ui to appear fitting the A4 page size but it appears very small that i didn't even see it at first glance. How do i make the widget ui fit the A4 paper size i set?

Upvotes: 0

Views: 2828

Answers (1)

Thalia
Thalia

Reputation: 14615

Set printer->setFullPage(true); in order to fit paper size

Upvotes: 0

Related Questions