printer.setOutputFileName('sample.pdf')
writer = QTextDocumentWriter()
writer.setFormat(writer.supportedDocumentFormats()[1])
writer.setFileName('sample.odt')
writer.write(doc)
How to generate reST/sphinx source from python?