import sys
import platform
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import (QCoreApplication, QPropertyAnimation, QDate, QDateTime, QMetaObject, QPoint, QRect, QSize,QTime, QUrl, QEvent)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPainter, QPixmap, QRadialGradient)
from PySide2.QtWidgets import *
from PySide2.QtCore import QFileInfo
from PySide2.QtPrintSupport import QPrinter
from ui_interface import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.start_btn.clicked.connect(lambda: self.ui.textEdit.setText("Hello World"))
self.ui.printbutton.clicked.connect(lambda: self.SavetoPDF())
self.show()
def SavetoPDF(self):
filename = QFileDialog.getSaveFileName(self, 'Save to PDF', None, 'PDF files(.pdf);; All Files')
if filename != "":
if QFileInfo(filename).suffix() == "": filename += '.pdf'
printer = QPrinter(QPrinter.HighResolution)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(filename)
print(self.ui.textEdit.document())
if __name__ == '__main__':
app = QApplication(sys.argv)`
window = MainWindow()
sys.exit(app.exec_())
exporting pdf from QtextEdit pyside2 .the print button works but the pdf its not saved in my computer it is blank
103 Views Asked by Hyston Kayange At
0