def print_file(fileName, printFunction):
 printer = QPrinter(QPrinter.HighResolution)
 printer.setPageSize(QPrinter.A4)
 printer.setOutputFileName(fileName)
 printer.setDocName(fileName)
 preview = QPrintPreviewDialog(printer)
 preview.paintRequested[QPrinter].connect(printFunction)
 size = QApplication.instance().desktop().screenGeometry()
 width = (size.width() - 100)
 height = (size.height() - 100)
 preview.setMinimumSize(width, height)
 preview.exec_()

def print_file ( fileName , printFunction ) : printer = QPrinter ( QPrinter . HighResolution ) printer . setPageSize ( QPrinter . A4 ) printer . setOutputFileName ( fileName ) printer . setDocName ( fileName ) preview = QPrintPreviewDialog ( printer ) preview . paintRequested [ QPrinter ] . connect ( printFunction ) size = QApplication . instance ( ) . desktop ( ) . screenGeometry ( ) width = ( size . width ( ) - 100 ) height = ( size . height ( ) - 100 ) preview . setMinimumSize ( width , height ) preview . exec_ ( )
this method print a file this method print a file .