Hi,
I did this, but it doesn't create sample.pdf as desired.

Qt Code:
  1. QPrinter printer;
  2. printer.setOutputFormat(QPrinter::PdfFormat);
  3. printer.setOutputFileName("C:/sample.pdf");
  4. printer.setPageSize(QPrinter::A4);
  5.  
  6. QPixmap myPix = QPixmap::grabWidget(this);
  7. QPainter painter;
  8. painter.begin(&printer);
  9. painter.drawPixmap(0, 0, myPix);
  10. painter.end();
To copy to clipboard, switch view to plain text mode